aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-08 21:21:10 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-08 21:21:10 +0200
commit80c5b6893d4708b3683ad9a51c990a326a8f1dff (patch)
tree0c4c3192e77e6afa1a1d47e750a0840d3a4ca60e
parentb8709032a3fb57b3ec536bdf9b92b526ed63b995 (diff)
downloadbusybox-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>
-rw-r--r--editors/patch.c2
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/read_printf.c12
-rw-r--r--mailutils/mail.c4
-rw-r--r--printutils/lpd.c2
-rw-r--r--shell/ash.c8
-rw-r--r--shell/shell_common.c2
-rw-r--r--util-linux/acpid.c2
8 files changed, 19 insertions, 17 deletions
diff --git a/editors/patch.c b/editors/patch.c
index a90252a03..6d3f319b0 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -239,7 +239,7 @@ static int apply_one_hunk(void)
plist = TT.current_hunk;
buf = NULL;
if (reverse ? TT.oldlen : TT.newlen) for (;;) {
- char *data = xmalloc_reads(TT.filein, NULL, NULL);
+ char *data = xmalloc_reads(TT.filein, NULL);
TT.linenum++;
diff --git a/include/libbb.h b/include/libbb.h
index 34f7f6a8b..4ea94e77f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -672,7 +672,7 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
-extern ssize_t nonblock_safe_read(int fd, void *buf, size_t count) FAST_FUNC;
+extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
// NB: will return short read on error, not -1,
// if some data was read before error occurred
extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC;
@@ -683,7 +683,7 @@ extern ssize_t open_read_close(const char *filename, void *buf, size_t maxsz) FA
// 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).
-extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC;
+extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC;
/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
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;
diff --git a/mailutils/mail.c b/mailutils/mail.c
index 44957016f..66c79471f 100644
--- a/mailutils/mail.c
+++ b/mailutils/mail.c
@@ -172,8 +172,8 @@ void FAST_FUNC get_cred_or_die(int fd)
G.user = xstrdup(bb_ask(fd, /* timeout: */ 0, "User: "));
G.pass = xstrdup(bb_ask(fd, /* timeout: */ 0, "Password: "));
} else {
- G.user = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL);
- G.pass = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL);
+ G.user = xmalloc_reads(fd, /* maxsize: */ NULL);
+ G.pass = xmalloc_reads(fd, /* maxsize: */ NULL);
}
if (!G.user || !*G.user || !G.pass)
bb_error_msg_and_die("no username or password");
diff --git a/printutils/lpd.c b/printutils/lpd.c
index 115552e0b..642e8a89e 100644
--- a/printutils/lpd.c
+++ b/printutils/lpd.c
@@ -102,7 +102,7 @@ static char *xmalloc_read_stdin(void)
{
// SECURITY:
size_t max = 4 * 1024; // more than enough for commands!
- return xmalloc_reads(STDIN_FILENO, NULL, &max);
+ return xmalloc_reads(STDIN_FILENO, &max);
}
int lpd_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
diff --git a/shell/ash.c b/shell/ash.c
index b50e0952e..b1b11bd1b 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5918,7 +5918,7 @@ expbackq(union node *cmd, int quoted, int quotes)
read:
if (in.fd < 0)
break;
- i = nonblock_safe_read(in.fd, buf, sizeof(buf));
+ i = nonblock_immune_read(in.fd, buf, sizeof(buf));
TRACE(("expbackq: read returns %d\n", i));
if (i <= 0)
break;
@@ -9617,7 +9617,7 @@ preadfd(void)
#if ENABLE_FEATURE_EDITING
retry:
if (!iflag || g_parsefile->pf_fd != STDIN_FILENO)
- nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
+ nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
else {
int timeout = -1;
# if ENABLE_ASH_IDLE_TIMEOUT
@@ -9663,10 +9663,10 @@ preadfd(void)
}
}
#else
- nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
+ nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
#endif
-#if 0 /* disabled: nonblock_safe_read() handles this problem */
+#if 0 /* disabled: nonblock_immune_read() handles this problem */
if (nr < 0) {
if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
int flags = fcntl(0, F_GETFL);
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 68659abd3..86a6493ed 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -170,7 +170,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
if ((bufpos & 0xff) == 0)
buffer = xrealloc(buffer, bufpos + 0x100);
- if (nonblock_safe_read(fd, &buffer[bufpos], 1) != 1) {
+ if (nonblock_immune_read(fd, &buffer[bufpos], 1) != 1) {
retval = (const char *)(uintptr_t)1;
break;
}
diff --git a/util-linux/acpid.c b/util-linux/acpid.c
index c9eed2a7f..4b7e5cacb 100644
--- a/util-linux/acpid.c
+++ b/util-linux/acpid.c
@@ -283,7 +283,7 @@ int acpid_main(int argc UNUSED_PARAM, char **argv)
char *buf;
int len;
- buf = xmalloc_reads(pfd[i].fd, NULL, NULL);
+ buf = xmalloc_reads(pfd[i].fd, NULL);
/* buf = "button/power PWRB 00000080 00000000" */
len = strlen(buf) - 9;
if (len >= 0)