aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/os_file.h
blob: 1972beba32b11ae2ab04a0b2f5f8a55642df9898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright 2019 Intel Corporation
 * SPDX-License-Identifier: MIT
 *
 * File operations helpers
 */

#ifndef _OS_FILE_H_
#define _OS_FILE_H_

#include <stdbool.h>
#include <stdio.h>

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * Create a new file and opens it for writing-only.
 * If the given filename already exists, nothing is done and NULL is returned.
 * `errno` gets set to the failure reason; if that is not EEXIST, the caller
 * might want to do something other than trying again.
 */
FILE *
os_file_create_unique(const char *filename, int filemode);

/*
 * Read a file.
 * Returns a char* that the caller must free(), or NULL and sets errno.
 */
char *
os_read_file(const char *filename);

/*
 * Returns true if the two file descriptors passed in can be determined to
 * reference the same file description, false otherwise
 */
bool
os_same_file_description(int fd1, int fd2);

#ifdef __cplusplus
}
#endif

#endif /* _OS_FILE_H_ */