Tracing for tdb operations.
[ccan] / ccan / read_write_all / read_write_all.c
1 #include "read_write_all.h"
2 #include <unistd.h>
3 #include <errno.h>
4
5 bool write_all(int fd, const void *data, size_t size)
6 {
7         while (size) {
8                 ssize_t done;
9
10                 done = write(fd, data, size);
11                 if (done < 0 && errno == EINTR)
12                         continue;
13                 if (done <= 0)
14                         return false;
15                 data += done;
16                 size -= done;
17         }
18
19         return true;
20 }
21
22 bool read_all(int fd, void *data, size_t size)
23 {
24         while (size) {
25                 ssize_t done;
26
27                 done = read(fd, data, size);
28                 if (done < 0 && errno == EINTR)
29                         continue;
30                 if (done <= 0)
31                         return false;
32                 data += done;
33                 size -= done;
34         }
35
36         return true;
37 }
38