diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-13 17:51:40 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-13 17:51:40 +0000 |
commit | a89d50fb9addfe0060f697a7e1d31a7b3010b2bb (patch) | |
tree | 81b252e0f0a931b1485eaefd89e900859ec8fcfb | |
parent | 130f559f4dcb64fc7dbf55aebaf0def4f601ac2f (diff) | |
download | busybox-w32-a89d50fb9addfe0060f697a7e1d31a7b3010b2bb.tar.gz busybox-w32-a89d50fb9addfe0060f697a7e1d31a7b3010b2bb.tar.bz2 busybox-w32-a89d50fb9addfe0060f697a7e1d31a7b3010b2bb.zip |
tr: properly detect read errors (Fernando Silveira <fsilveira@gmail.com>)
readprofile: use xwrite
function old new delta
tr_main 679 677 -2
readprofile_main 1964 1944 -20
-rw-r--r-- | coreutils/tr.c | 8 | ||||
-rw-r--r-- | util-linux/readprofile.c | 5 |
2 files changed, 6 insertions, 7 deletions
diff --git a/coreutils/tr.c b/coreutils/tr.c index 9521bbcd5..e60e08b25 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c | |||
@@ -173,7 +173,8 @@ int tr_main(int argc, char **argv) | |||
173 | int idx = 1; | 173 | int idx = 1; |
174 | int i; | 174 | int i; |
175 | smalluint flags = 0; | 175 | smalluint flags = 0; |
176 | size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1; | 176 | ssize_t read_chars = 0; |
177 | size_t in_index = 0, out_index = 0, c, coded, last = -1; | ||
177 | RESERVE_CONFIG_UBUFFER(output, BUFSIZ); | 178 | RESERVE_CONFIG_UBUFFER(output, BUFSIZ); |
178 | RESERVE_CONFIG_BUFFER(vector, ASCII+1); | 179 | RESERVE_CONFIG_BUFFER(vector, ASCII+1); |
179 | RESERVE_CONFIG_BUFFER(invec, ASCII+1); | 180 | RESERVE_CONFIG_BUFFER(invec, ASCII+1); |
@@ -223,8 +224,9 @@ int tr_main(int argc, char **argv) | |||
223 | } | 224 | } |
224 | read_chars = read(STDIN_FILENO, tr_buf, BUFSIZ); | 225 | read_chars = read(STDIN_FILENO, tr_buf, BUFSIZ); |
225 | if (read_chars <= 0) { | 226 | if (read_chars <= 0) { |
226 | if (write(STDOUT_FILENO, (char *)output, out_index) != out_index) | 227 | xwrite(STDOUT_FILENO, (char *)output, out_index); |
227 | bb_perror_msg(bb_msg_write_error); | 228 | if (read_chars < 0) |
229 | bb_perror_msg_and_die(bb_msg_read_error); | ||
228 | exit(EXIT_SUCCESS); | 230 | exit(EXIT_SUCCESS); |
229 | } | 231 | } |
230 | in_index = 0; | 232 | in_index = 0; |
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index dbe7c7171..c6152558c 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c | |||
@@ -88,10 +88,7 @@ int readprofile_main(int argc, char **argv) | |||
88 | } | 88 | } |
89 | 89 | ||
90 | fd = xopen(defaultpro, O_WRONLY); | 90 | fd = xopen(defaultpro, O_WRONLY); |
91 | 91 | xwrite(fd, &multiplier, to_write); | |
92 | if (full_write(fd, &multiplier, to_write) != to_write) | ||
93 | bb_perror_msg_and_die("error writing %s", defaultpro); | ||
94 | |||
95 | close(fd); | 92 | close(fd); |
96 | return EXIT_SUCCESS; | 93 | return EXIT_SUCCESS; |
97 | } | 94 | } |