]> wimlib.net Git - wimlib/blob - include/wimlib/file_io.h
file_io.c: Remove unused full_writev()
[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 #ifndef __WIN32__
45 #  define O_BINARY 0
46 #endif
47
48 extern off_t
49 filedes_seek(struct filedes *fd, off_t offset);
50
51 extern bool
52 filedes_is_seekable(struct filedes *fd);
53
54 static inline void filedes_init(struct filedes *fd, int raw_fd)
55 {
56         fd->fd = raw_fd;
57         fd->offset = 0;
58         fd->is_pipe = 0;
59 }
60
61 static inline void filedes_invalidate(struct filedes *fd)
62 {
63         fd->fd = -1;
64 }
65
66 static inline void filedes_copy(struct filedes *dst, const struct filedes *src)
67 {
68         *dst = *src;
69 }
70
71 #define filedes_close(f) close((f)->fd)
72
73 static inline bool
74 filedes_valid(const struct filedes *fd)
75 {
76         return fd->fd != -1;
77 }
78
79 #endif /* _WIMLIB_FILE_IO_H */