util/list: Add a list pair iterator
[mesa.git] / src / util / os_file.h
1 /*
2 * Copyright 2019 Intel Corporation
3 * SPDX-License-Identifier: MIT
4 *
5 * File operations helpers
6 */
7
8 #ifndef _OS_FILE_H_
9 #define _OS_FILE_H_
10
11 #include <stdbool.h>
12 #include <stdio.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /*
19 * Create a new file and opens it for writing-only.
20 * If the given filename already exists, nothing is done and NULL is returned.
21 * `errno` gets set to the failure reason; if that is not EEXIST, the caller
22 * might want to do something other than trying again.
23 */
24 FILE *
25 os_file_create_unique(const char *filename, int filemode);
26
27 /*
28 * Read a file.
29 * Returns a char* that the caller must free(), or NULL and sets errno.
30 * If size is not null and no error occured it's set to the size of the
31 * file.
32 */
33 char *
34 os_read_file(const char *filename, size_t *size);
35
36 /*
37 * Try to determine if two file descriptors reference the same file description
38 *
39 * Return values:
40 * - 0: They reference the same file description
41 * - > 0: They do not reference the same file description
42 * - < 0: Unable to determine whether they reference the same file description
43 */
44 int
45 os_same_file_description(int fd1, int fd2);
46
47 #ifdef __cplusplus
48 }
49 #endif
50
51 #endif /* _OS_FILE_H_ */