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 | |
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>
-rw-r--r-- | editors/patch.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/read_printf.c | 12 | ||||
-rw-r--r-- | mailutils/mail.c | 4 | ||||
-rw-r--r-- | printutils/lpd.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 8 | ||||
-rw-r--r-- | shell/shell_common.c | 2 | ||||
-rw-r--r-- | util-linux/acpid.c | 2 |
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) | |||
239 | plist = TT.current_hunk; | 239 | plist = TT.current_hunk; |
240 | buf = NULL; | 240 | buf = NULL; |
241 | if (reverse ? TT.oldlen : TT.newlen) for (;;) { | 241 | if (reverse ? TT.oldlen : TT.newlen) for (;;) { |
242 | char *data = xmalloc_reads(TT.filein, NULL, NULL); | 242 | char *data = xmalloc_reads(TT.filein, NULL); |
243 | 243 | ||
244 | TT.linenum++; | 244 | TT.linenum++; |
245 | 245 | ||
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 | |||
672 | 672 | ||
673 | 673 | ||
674 | extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; | 674 | extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; |
675 | extern ssize_t nonblock_safe_read(int fd, void *buf, size_t count) FAST_FUNC; | 675 | extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC; |
676 | // NB: will return short read on error, not -1, | 676 | // NB: will return short read on error, not -1, |
677 | // if some data was read before error occurred | 677 | // if some data was read before error occurred |
678 | extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC; | 678 | 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 | |||
683 | // Reads one line a-la fgets (but doesn't save terminating '\n'). | 683 | // Reads one line a-la fgets (but doesn't save terminating '\n'). |
684 | // Reads byte-by-byte. Useful when it is important to not read ahead. | 684 | // Reads byte-by-byte. Useful when it is important to not read ahead. |
685 | // Bytes are appended to pfx (which must be malloced, or NULL). | 685 | // Bytes are appended to pfx (which must be malloced, or NULL). |
686 | extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC; | 686 | extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC; |
687 | /* Reads block up to *maxsz_p (default: INT_MAX - 4095) */ | 687 | /* Reads block up to *maxsz_p (default: INT_MAX - 4095) */ |
688 | extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 688 | extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
689 | /* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */ | 689 | /* 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 @@ | |||
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; |
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) | |||
172 | G.user = xstrdup(bb_ask(fd, /* timeout: */ 0, "User: ")); | 172 | G.user = xstrdup(bb_ask(fd, /* timeout: */ 0, "User: ")); |
173 | G.pass = xstrdup(bb_ask(fd, /* timeout: */ 0, "Password: ")); | 173 | G.pass = xstrdup(bb_ask(fd, /* timeout: */ 0, "Password: ")); |
174 | } else { | 174 | } else { |
175 | G.user = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL); | 175 | G.user = xmalloc_reads(fd, /* maxsize: */ NULL); |
176 | G.pass = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL); | 176 | G.pass = xmalloc_reads(fd, /* maxsize: */ NULL); |
177 | } | 177 | } |
178 | if (!G.user || !*G.user || !G.pass) | 178 | if (!G.user || !*G.user || !G.pass) |
179 | bb_error_msg_and_die("no username or password"); | 179 | 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) | |||
102 | { | 102 | { |
103 | // SECURITY: | 103 | // SECURITY: |
104 | size_t max = 4 * 1024; // more than enough for commands! | 104 | size_t max = 4 * 1024; // more than enough for commands! |
105 | return xmalloc_reads(STDIN_FILENO, NULL, &max); | 105 | return xmalloc_reads(STDIN_FILENO, &max); |
106 | } | 106 | } |
107 | 107 | ||
108 | int lpd_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; | 108 | 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) | |||
5918 | read: | 5918 | read: |
5919 | if (in.fd < 0) | 5919 | if (in.fd < 0) |
5920 | break; | 5920 | break; |
5921 | i = nonblock_safe_read(in.fd, buf, sizeof(buf)); | 5921 | i = nonblock_immune_read(in.fd, buf, sizeof(buf)); |
5922 | TRACE(("expbackq: read returns %d\n", i)); | 5922 | TRACE(("expbackq: read returns %d\n", i)); |
5923 | if (i <= 0) | 5923 | if (i <= 0) |
5924 | break; | 5924 | break; |
@@ -9617,7 +9617,7 @@ preadfd(void) | |||
9617 | #if ENABLE_FEATURE_EDITING | 9617 | #if ENABLE_FEATURE_EDITING |
9618 | retry: | 9618 | retry: |
9619 | if (!iflag || g_parsefile->pf_fd != STDIN_FILENO) | 9619 | if (!iflag || g_parsefile->pf_fd != STDIN_FILENO) |
9620 | nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1); | 9620 | nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1); |
9621 | else { | 9621 | else { |
9622 | int timeout = -1; | 9622 | int timeout = -1; |
9623 | # if ENABLE_ASH_IDLE_TIMEOUT | 9623 | # if ENABLE_ASH_IDLE_TIMEOUT |
@@ -9663,10 +9663,10 @@ preadfd(void) | |||
9663 | } | 9663 | } |
9664 | } | 9664 | } |
9665 | #else | 9665 | #else |
9666 | nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1); | 9666 | nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1); |
9667 | #endif | 9667 | #endif |
9668 | 9668 | ||
9669 | #if 0 /* disabled: nonblock_safe_read() handles this problem */ | 9669 | #if 0 /* disabled: nonblock_immune_read() handles this problem */ |
9670 | if (nr < 0) { | 9670 | if (nr < 0) { |
9671 | if (parsefile->fd == 0 && errno == EWOULDBLOCK) { | 9671 | if (parsefile->fd == 0 && errno == EWOULDBLOCK) { |
9672 | int flags = fcntl(0, F_GETFL); | 9672 | 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), | |||
170 | 170 | ||
171 | if ((bufpos & 0xff) == 0) | 171 | if ((bufpos & 0xff) == 0) |
172 | buffer = xrealloc(buffer, bufpos + 0x100); | 172 | buffer = xrealloc(buffer, bufpos + 0x100); |
173 | if (nonblock_safe_read(fd, &buffer[bufpos], 1) != 1) { | 173 | if (nonblock_immune_read(fd, &buffer[bufpos], 1) != 1) { |
174 | retval = (const char *)(uintptr_t)1; | 174 | retval = (const char *)(uintptr_t)1; |
175 | break; | 175 | break; |
176 | } | 176 | } |
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) | |||
283 | char *buf; | 283 | char *buf; |
284 | int len; | 284 | int len; |
285 | 285 | ||
286 | buf = xmalloc_reads(pfd[i].fd, NULL, NULL); | 286 | buf = xmalloc_reads(pfd[i].fd, NULL); |
287 | /* buf = "button/power PWRB 00000080 00000000" */ | 287 | /* buf = "button/power PWRB 00000080 00000000" */ |
288 | len = strlen(buf) - 9; | 288 | len = strlen(buf) - 9; |
289 | if (len >= 0) | 289 | if (len >= 0) |