summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2011-05-08 21:21:10 +0200
committerDenys Vlasenko2011-05-08 21:21:10 +0200
commit80c5b6893d4708b3683ad9a51c990a326a8f1dff (patch)
tree0c4c3192e77e6afa1a1d47e750a0840d3a4ca60e /libbb
parentb8709032a3fb57b3ec536bdf9b92b526ed63b995 (diff)
downloadbusybox-80c5b6893d4708b3683ad9a51c990a326a8f1dff.zip
busybox-80c5b6893d4708b3683ad9a51c990a326a8f1dff.tar.gz
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.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libbb/read_printf.c b/libbb/read_printf.c
index 8664bc6..0e6fbf6 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;