diff options
| author | ZyX <kp-pav@yandex.ru> | 2016-06-01 22:57:52 +0300 | 
|---|---|---|
| committer | ZyX <kp-pav@yandex.ru> | 2016-06-23 21:17:51 +0300 | 
| commit | 11dda658d6f0c4470a54012df71be73b4e9a5f57 (patch) | |
| tree | abdc359b9f730253893f60d11c85af39d74e6308 /src/nvim/file.h | |
| parent | 65af001f2bcc35f19d64b4d2c1dbcd46d87432e8 (diff) | |
| download | rneovim-11dda658d6f0c4470a54012df71be73b4e9a5f57.tar.gz rneovim-11dda658d6f0c4470a54012df71be73b4e9a5f57.tar.bz2 rneovim-11dda658d6f0c4470a54012df71be73b4e9a5f57.zip | |
file,os/fs,shada: Separate opening, closing, writing and reading files
Moves low-level functions handling to os/fs.c. Adds file.c with a proxy
interface.
Target: while leaving syscalls handling is os.c (partially handled by libuv),
add buffering for reading and writing to file.c.
Diffstat (limited to 'src/nvim/file.h')
| -rw-r--r-- | src/nvim/file.h | 59 | 
1 files changed, 59 insertions, 0 deletions
| diff --git a/src/nvim/file.h b/src/nvim/file.h new file mode 100644 index 0000000000..0aa98e0def --- /dev/null +++ b/src/nvim/file.h @@ -0,0 +1,59 @@ +#ifndef NVIM_FILE_H +#define NVIM_FILE_H + +#include <stdbool.h> +#include <stddef.h> +#include <fcntl.h> + +#include "nvim/func_attr.h" + +/// Structure used to read from/write to file +typedef struct { +  int fd;  ///< File descriptor. +  bool eof;  ///< True if end of file was encountered. +} FileDescriptor; + +/// file_open() flags +typedef enum { +  FILE_READ_ONLY = O_RDONLY,  ///< Open file read-only. +  FILE_CREATE = O_CREAT,  ///< Create file if it does not exist yet. +  FILE_WRITE_ONLY = O_WRONLY,  ///< Open file for writing only. +#ifdef O_NOFOLLOW +  FILE_NOSYMLINK = O_NOFOLLOW,  ///< Do not allow symbolic links. +#else +  FILE_NOSYMLINK = 0, +#endif +  FILE_CREATE_ONLY = O_CREAT|O_EXCL,  ///< Only create the file, failing +                                      ///< if it already exists. +  FILE_TRUNCATE = O_TRUNC,  ///< Truncate the file if it exists. +} FileOpenFlags; + +/// Check whether end of file was encountered +/// +/// @param[in]  fp  File to check. +/// +/// @return true if it was, false if it was not or read operation was never +///         performed. +static inline bool file_eof(const FileDescriptor *const fp) +  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL +  FUNC_ATTR_ALWAYS_INLINE +{ +  return fp->eof && rbuffer_size(fp->rv) == 0; +} + +/// Return the file descriptor associated with the FileDescriptor structure +/// +/// @param[in]  fp  File to check. +/// +/// @return File descriptor. +static inline int file_fd(const FileDescriptor *const fp) +  FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL +  FUNC_ATTR_ALWAYS_INLINE +{ +  return fp->fd; +} + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "file.h.generated.h" +#endif +#endif  // NVIM_FILE_H | 
