diff options
Diffstat (limited to 'src/main/extractor_common.c')
-rw-r--r-- | src/main/extractor_common.c | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/main/extractor_common.c b/src/main/extractor_common.c index 866609e..59524b3 100644 --- a/src/main/extractor_common.c +++ b/src/main/extractor_common.c | |||
@@ -39,27 +39,27 @@ | |||
39 | * @param buf buffer to read from | 39 | * @param buf buffer to read from |
40 | * @param size number of bytes to write | 40 | * @param size number of bytes to write |
41 | * @return number of bytes written (that is 'size'), or -1 on error | 41 | * @return number of bytes written (that is 'size'), or -1 on error |
42 | */ | 42 | */ |
43 | ssize_t | 43 | ssize_t |
44 | EXTRACTOR_write_all_ (int fd, | 44 | EXTRACTOR_write_all_ (int fd, |
45 | const void *buf, | 45 | const void *buf, |
46 | size_t size) | 46 | size_t size) |
47 | { | 47 | { |
48 | const char *data = buf; | 48 | const char *data = buf; |
49 | size_t off = 0; | 49 | size_t off = 0; |
50 | ssize_t ret; | 50 | ssize_t ret; |
51 | 51 | ||
52 | while (off < size) | 52 | while (off < size) |
53 | { | ||
54 | ret = write (fd, &data[off], size - off); | ||
55 | if (ret <= 0) | ||
53 | { | 56 | { |
54 | ret = write (fd, &data[off], size - off); | 57 | if (-1 == ret) |
55 | if (ret <= 0) | 58 | LOG_STRERROR ("write"); |
56 | { | 59 | return -1; |
57 | if (-1 == ret) | ||
58 | LOG_STRERROR ("write"); | ||
59 | return -1; | ||
60 | } | ||
61 | off += ret; | ||
62 | } | 60 | } |
61 | off += ret; | ||
62 | } | ||
63 | return size; | 63 | return size; |
64 | } | 64 | } |
65 | 65 | ||
@@ -74,28 +74,27 @@ EXTRACTOR_write_all_ (int fd, | |||
74 | */ | 74 | */ |
75 | ssize_t | 75 | ssize_t |
76 | EXTRACTOR_read_all_ (int fd, | 76 | EXTRACTOR_read_all_ (int fd, |
77 | void *buf, | 77 | void *buf, |
78 | size_t size) | 78 | size_t size) |
79 | { | 79 | { |
80 | char *data = buf; | 80 | char *data = buf; |
81 | size_t off = 0; | 81 | size_t off = 0; |
82 | ssize_t ret; | 82 | ssize_t ret; |
83 | 83 | ||
84 | while (off < size) | 84 | while (off < size) |
85 | { | ||
86 | ret = read (fd, &data[off], size - off); | ||
87 | if (ret <= 0) | ||
85 | { | 88 | { |
86 | ret = read (fd, &data[off], size - off); | 89 | if (-1 == ret) |
87 | if (ret <= 0) | 90 | LOG_STRERROR ("write"); |
88 | { | 91 | return -1; |
89 | if (-1 == ret) | ||
90 | LOG_STRERROR ("write"); | ||
91 | return -1; | ||
92 | } | ||
93 | off += ret; | ||
94 | } | 92 | } |
93 | off += ret; | ||
94 | } | ||
95 | return size; | 95 | return size; |
96 | |||
97 | } | ||
98 | 96 | ||
97 | } | ||
99 | 98 | ||
100 | 99 | ||
101 | /* end of extractor_common.c */ | 100 | /* end of extractor_common.c */ |