]> wimlib.net Git - wimlib/blobdiff - include/wimlib/file_io.h
Remove quotes in do_load_text_file()
[wimlib] / include / wimlib / file_io.h
index 1d258983354d2e5f95964d740fced0aa87e6840d..01f971783d28e7408c52a535c2f667cafa69e8db 100644 (file)
@@ -3,19 +3,34 @@
 
 #include <stddef.h>
 #include <sys/types.h>
+#include <stdbool.h>
 
-extern size_t
-full_read(int fd, void *buf, size_t n);
+/* Wrapper around a file descriptor that keeps track of offset (including in
+ * pipes, which don't support lseek()) and a cached flag that tells whether the
+ * file descriptor is a pipe or not.  */
+struct filedes {
+       int fd;
+       unsigned int is_pipe : 1;
+       off_t offset;
+};
+
+extern int
+full_read(struct filedes *fd, void *buf, size_t n);
 
-extern size_t
-full_write(int fd, const void *buf, size_t n);
+extern int
+full_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset);
 
-extern size_t
-full_pread(int fd, void *buf, size_t nbyte, off_t offset);
+extern int
+full_write(struct filedes *fd, const void *buf, size_t n);
 
-extern size_t
-full_pwrite(int fd, const void *buf, size_t count, off_t offset);
+extern int
+full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
 
+extern ssize_t
+raw_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset);
+
+extern ssize_t
+raw_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
 
 #ifdef __WIN32__
 struct iovec {
@@ -26,14 +41,42 @@ struct iovec {
 struct iovec;
 #endif
 
-extern size_t
-full_writev(int fd, struct iovec *iov, int iovcnt);
-
-extern off_t
-filedes_offset(int fd);
+extern int
+full_writev(struct filedes *fd, struct iovec *iov, int iovcnt);
 
 #ifndef __WIN32__
 #  define O_BINARY 0
 #endif
 
+extern off_t
+filedes_seek(struct filedes *fd, off_t offset);
+
+extern bool
+filedes_is_seekable(struct filedes *fd);
+
+static inline void filedes_init(struct filedes *fd, int raw_fd)
+{
+       fd->fd = raw_fd;
+       fd->offset = 0;
+       fd->is_pipe = 0;
+}
+
+static inline void filedes_invalidate(struct filedes *fd)
+{
+       fd->fd = -1;
+}
+
+static inline void filedes_copy(struct filedes *dst, const struct filedes *src)
+{
+       *dst = *src;
+}
+
+#define filedes_close(f) close((f)->fd)
+
+static inline bool
+filedes_valid(const struct filedes *fd)
+{
+       return fd->fd != -1;
+}
+
 #endif /* _WIMLIB_FILE_IO_H */