#ifndef __FILEUTIL_H__ # define __FILEUTIL_H__ #ifdef __cplusplus extern "C" { #endif #include #include #include /* Open a file descriptor in a pre-allocated FILE. */ int __fp_open(FILE *fp, int fd, bool use_buffering); /* Close fp and free all of its resources. */ void __fp_close(FILE *fp, bool free_fp); /* Reads data from a file descriptor; updates the fdpos and sets the error indicator. Returns 0 on success, EOF on error. */ ssize_t __fp_read(FILE *fp, void *data, size_t size); /* Write data to a file descriptor; updates the fdpos and sets the error indicator. Returns 0 on success, EOF on error. */ ssize_t __fp_write(FILE *fp, void const *data, size_t size); /* Parse mode bits. Returns corresponding open() flags if successful, -1 if the mode is invalid. If [fp != NULL], also sets the fields of [fp]. Sets errno = EINVAL in case of error. */ int __fp_parse_mode(char const *mode, FILE *fp); #ifdef __cplusplus } #endif #endif /*__FILEUTIL_H__*/