diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-08 21:21:10 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-05-08 21:21:10 +0200 |
commit | 80c5b6893d4708b3683ad9a51c990a326a8f1dff (patch) | |
tree | 0c4c3192e77e6afa1a1d47e750a0840d3a4ca60e /libbb | |
parent | b8709032a3fb57b3ec536bdf9b92b526ed63b995 (diff) | |
download | busybox-w32-80c5b6893d4708b3683ad9a51c990a326a8f1dff.tar.gz busybox-w32-80c5b6893d4708b3683ad9a51c990a326a8f1dff.tar.bz2 busybox-w32-80c5b6893d4708b3683ad9a51c990a326a8f1dff.zip |
libbb: nonblock_safe_read->nonblock_immune_read, remove unused param of xmalloc_reads
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/read_printf.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libbb/read_printf.c b/libbb/read_printf.c index 8664bc625..0e6fbf662 100644 --- a/libbb/read_printf.c +++ b/libbb/read_printf.c | |||
@@ -55,7 +55,7 @@ | |||
55 | * which detects EAGAIN and uses poll() to wait on the fd. | 55 | * which detects EAGAIN and uses poll() to wait on the fd. |
56 | * Thankfully, poll() doesn't care about O_NONBLOCK flag. | 56 | * Thankfully, poll() doesn't care about O_NONBLOCK flag. |
57 | */ | 57 | */ |
58 | ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count) | 58 | ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count) |
59 | { | 59 | { |
60 | struct pollfd pfd[1]; | 60 | struct pollfd pfd[1]; |
61 | ssize_t n; | 61 | ssize_t n; |
@@ -74,13 +74,15 @@ ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count) | |||
74 | // Reads one line a-la fgets (but doesn't save terminating '\n'). | 74 | // Reads one line a-la fgets (but doesn't save terminating '\n'). |
75 | // Reads byte-by-byte. Useful when it is important to not read ahead. | 75 | // Reads byte-by-byte. Useful when it is important to not read ahead. |
76 | // Bytes are appended to pfx (which must be malloced, or NULL). | 76 | // Bytes are appended to pfx (which must be malloced, or NULL). |
77 | char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p) | 77 | char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p) |
78 | { | 78 | { |
79 | char *p; | 79 | char *p; |
80 | size_t sz = buf ? strlen(buf) : 0; | 80 | char *buf = NULL; |
81 | size_t sz = 0; | ||
81 | size_t maxsz = maxsz_p ? *maxsz_p : (INT_MAX - 4095); | 82 | size_t maxsz = maxsz_p ? *maxsz_p : (INT_MAX - 4095); |
82 | 83 | ||
83 | goto jump_in; | 84 | goto jump_in; |
85 | |||
84 | while (sz < maxsz) { | 86 | while (sz < maxsz) { |
85 | if ((size_t)(p - buf) == sz) { | 87 | if ((size_t)(p - buf) == sz) { |
86 | jump_in: | 88 | jump_in: |
@@ -88,8 +90,8 @@ char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p) | |||
88 | p = buf + sz; | 90 | p = buf + sz; |
89 | sz += 128; | 91 | sz += 128; |
90 | } | 92 | } |
91 | /* nonblock_safe_read() because we are used by e.g. shells */ | 93 | if (nonblock_immune_read(fd, p, 1) != 1) { |
92 | if (nonblock_safe_read(fd, p, 1) != 1) { /* EOF/error */ | 94 | /* EOF/error */ |
93 | if (p == buf) { /* we read nothing */ | 95 | if (p == buf) { /* we read nothing */ |
94 | free(buf); | 96 | free(buf); |
95 | return NULL; | 97 | return NULL; |