neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

fileio_defs.h (1398B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stdint.h>
      5 
      6 /// Structure used to read from/write to file
      7 typedef struct {
      8  int fd;             ///< File descriptor. Can be -1 if no backing file (file_open_buffer)
      9  char *buffer;       ///< Read or write buffer. always ARENA_BLOCK_SIZE if allocated
     10  char *read_pos;     ///< read position in buffer
     11  char *write_pos;    ///< write position in buffer
     12  bool wr;            ///< True if file is in write mode.
     13  bool eof;           ///< True if end of file was encountered.
     14  bool non_blocking;  ///< True if EAGAIN should not restart syscalls.
     15  uint64_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.
     26 static inline bool file_eof(const FileDescriptor *const fp)
     27  FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
     28 {
     29  return 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.
     37 static inline int file_fd(const FileDescriptor *const fp)
     38  FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
     39 {
     40  return fp->fd;
     41 }