| 1 |
/// @file |
| 2 |
/// @brief wrapper around `fopen` for internal library usage |
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <util/api.h> |
| 8 |
|
| 9 |
#ifdef __cplusplus |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
/// open a file, setting close-on-exec |
| 14 |
/// |
| 15 |
/// Generally, library code should set close-on-exec (`O_CLOEXEC`) on file |
| 16 |
/// descriptors it creates to avoid child processes of concurrent `fork`+`exec` |
| 17 |
/// operations accidentally inheriting copies of the descriptors. It is tricky |
| 18 |
/// to achieve this without races. This function attempts to avoid the common |
| 19 |
/// problems when trying to do this with `fopen`. |
| 20 |
/// |
| 21 |
/// @param filename A filename, as you would pass to `fopen` |
| 22 |
/// @param mode A mode, as you would pass to `fopen` |
| 23 |
/// @return A file handle with close-on-exit set on success or `NULL` on failure |
| 24 |
UTIL_API FILE *gv_fopen(const char *filename, const char *mode); |
| 25 |
|
| 26 |
#ifdef __cplusplus |
| 27 |
} |
| 28 |
#endif |