robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
38986188ba
master
1#pragma once 2 3#include <stdbool.h> 4#include <stdint.h> 5 6/// Structure used to read from/write to file 7typedef struct { 8int fd ;///< File descriptor. Can be -1 if no backing file (file_open_buffer) 9char * buffer ;///< Read or write buffer. always ARENA_BLOCK_SIZE if allocated 10char * read_pos ;///< read position in buffer 11char * write_pos ;///< write position in buffer 12bool wr ;///< True if file is in write mode. 13bool eof ;///< True if end of file was encountered. 14bool non_blocking ;///< True if EAGAIN should not restart syscalls. 15uint64_t bytes_read ;///< total bytes read so far 16}FileDescriptor ; 17 18#include "os/fileio_defs.h.inline.generated.h" 19 20/// Check whether end of file was encountered 21/// 22/// @param[in] fp File to check. 23/// 24/// @return true if it was, false if it was not or read operation was never 25/// performed. 26static inline bool file_eof (const FileDescriptor * const fp ) 27FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL 28{ 29return fp -> eof && fp -> read_pos == fp -> write_pos ; 30} 31 32/// Return the file descriptor associated with the FileDescriptor structure 33/// 34/// @param[in] fp File to check. 35/// 36/// @return File descriptor. 37static inline int file_fd (const FileDescriptor * const fp ) 38FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL 39{ 40return fp -> fd ; 41}