From 80c5b6893d4708b3683ad9a51c990a326a8f1dff Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 8 May 2011 21:21:10 +0200 Subject: libbb: nonblock_safe_read->nonblock_immune_read, remove unused param of xmalloc_reads Signed-off-by: Denys Vlasenko --- libbb/read_printf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libbb/read_printf.c') 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 @@ * which detects EAGAIN and uses poll() to wait on the fd. * Thankfully, poll() doesn't care about O_NONBLOCK flag. */ -ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count) +ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count) { struct pollfd pfd[1]; ssize_t n; @@ -74,13 +74,15 @@ ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count) // Reads one line a-la fgets (but doesn't save terminating '\n'). // Reads byte-by-byte. Useful when it is important to not read ahead. // Bytes are appended to pfx (which must be malloced, or NULL). -char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p) +char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p) { char *p; - size_t sz = buf ? strlen(buf) : 0; + char *buf = NULL; + size_t sz = 0; size_t maxsz = maxsz_p ? *maxsz_p : (INT_MAX - 4095); goto jump_in; + while (sz < maxsz) { if ((size_t)(p - buf) == sz) { jump_in: @@ -88,8 +90,8 @@ char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p) p = buf + sz; sz += 128; } - /* nonblock_safe_read() because we are used by e.g. shells */ - if (nonblock_safe_read(fd, p, 1) != 1) { /* EOF/error */ + if (nonblock_immune_read(fd, p, 1) != 1) { + /* EOF/error */ if (p == buf) { /* we read nothing */ free(buf); return NULL; -- cgit v1.2.3