]> wimlib.net Git - wimlib/blob - include/wimlib/file_io.h
Remove quotes in do_load_text_file()
[wimlib] / include / wimlib / file_io.h
1 #ifndef _WIMLIB_FILE_IO_H
2 #define _WIMLIB_FILE_IO_H
3
4 #include <stddef.h>
5 #include <sys/types.h>
6 #include <stdbool.h>
7
8 /* Wrapper around a file descriptor that keeps track of offset (including in
9  * pipes, which don't support lseek()) and a cached flag that tells whether the
10  * file descriptor is a pipe or not.  */
11 struct filedes {
12         int fd;
13         unsigned int is_pipe : 1;
14         off_t offset;
15 };
16
17 extern int
18 full_read(struct filedes *fd, void *buf, size_t n);
19
20 extern int
21 full_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset);
22
23 extern int
24 full_write(struct filedes *fd, const void *buf, size_t n);
25
26 extern int
27 full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
28
29 extern ssize_t
30 raw_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset);
31
32 extern ssize_t
33 raw_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
34
35 #ifdef __WIN32__
36 struct iovec {
37         void *iov_base;
38         size_t iov_len;
39 };
40 #else
41 struct iovec;
42 #endif
43
44 extern int
45 full_writev(struct filedes *fd, struct iovec *iov, int iovcnt);
46
47 #ifndef __WIN32__
48 #  define O_BINARY 0
49 #endif
50
51 extern off_t
52 filedes_seek(struct filedes *fd, off_t offset);
53
54 extern bool
55 filedes_is_seekable(struct filedes *fd);
56
57 static inline void filedes_init(struct filedes *fd, int raw_fd)
58 {
59         fd->fd = raw_fd;
60         fd->offset = 0;
61         fd->is_pipe = 0;
62 }
63
64 static inline void filedes_invalidate(struct filedes *fd)
65 {
66         fd->fd = -1;
67 }
68
69 static inline void filedes_copy(struct filedes *dst, const struct filedes *src)
70 {
71         *dst = *src;
72 }
73
74 #define filedes_close(f) close((f)->fd)
75
76 static inline bool
77 filedes_valid(const struct filedes *fd)
78 {
79         return fd->fd != -1;
80 }
81
82 #endif /* _WIMLIB_FILE_IO_H */