3 int read_in_full(int fd
, void *buf
, size_t count
)
9 ssize_t loaded
= xread(fd
, p
, count
);
11 return total
? total
: loaded
;
20 void read_or_die(int fd
, void *buf
, size_t count
)
24 loaded
= read_in_full(fd
, buf
, count
);
25 if (loaded
!= count
) {
27 die("read error (%s)", strerror(errno
));
28 die("read error: end of file");
32 int write_in_full(int fd
, const void *buf
, size_t count
)
38 size_t written
= xwrite(fd
, p
, count
);
53 void write_or_die(int fd
, const void *buf
, size_t count
)
55 if (write_in_full(fd
, buf
, count
) < 0) {
58 die("write error (%s)", strerror(errno
));
62 int write_or_whine_pipe(int fd
, const void *buf
, size_t count
, const char *msg
)
64 if (write_in_full(fd
, buf
, count
) < 0) {
67 fprintf(stderr
, "%s: write error (%s)\n",
68 msg
, strerror(errno
));
75 int write_or_whine(int fd
, const void *buf
, size_t count
, const char *msg
)
77 if (write_in_full(fd
, buf
, count
) < 0) {
78 fprintf(stderr
, "%s: write error (%s)\n",
79 msg
, strerror(errno
));