diff options
Diffstat (limited to '')
-rw-r--r-- | libbb/git.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libbb/git.c b/libbb/git.c index 3ca8a9424..668f8c118 100644 --- a/libbb/git.c +++ b/libbb/git.c | |||
@@ -1,13 +1,42 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | #include "git.h" | 2 | #include "git.h" |
3 | 3 | ||
4 | #define die bb_error_msg_and_die | ||
5 | |||
6 | /* | ||
7 | * xwrite() is the same a write(), but it automatically restarts write() | ||
8 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
9 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
10 | */ | ||
11 | ssize_t _xwrite(int fd, const void *buf, size_t len) | ||
12 | { | ||
13 | ssize_t nr; | ||
14 | while (1) { | ||
15 | nr = write(fd, buf, len); | ||
16 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
17 | continue; | ||
18 | return nr; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | ssize_t _xread(int fd, void *buf, size_t len) | ||
23 | { | ||
24 | ssize_t nr; | ||
25 | while (1) { | ||
26 | nr = read(fd, buf, len); | ||
27 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
28 | continue; | ||
29 | return nr; | ||
30 | } | ||
31 | } | ||
32 | |||
4 | ssize_t write_in_full(int fd, const void *buf, size_t count) | 33 | ssize_t write_in_full(int fd, const void *buf, size_t count) |
5 | { | 34 | { |
6 | const char *p = buf; | 35 | const char *p = buf; |
7 | ssize_t total = 0; | 36 | ssize_t total = 0; |
8 | 37 | ||
9 | while (count > 0) { | 38 | while (count > 0) { |
10 | ssize_t written = xwrite(fd, p, count); | 39 | ssize_t written = _xwrite(fd, p, count); |
11 | if (written < 0) | 40 | if (written < 0) |
12 | return -1; | 41 | return -1; |
13 | if (!written) { | 42 | if (!written) { |