diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-25 23:50:28 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-25 23:50:28 +0000 |
commit | a0f78c266b49e283f862a642ede1cc1ed439162a (patch) | |
tree | 9e5d35d70aa35b0a06248c5d1189e8eb274083b0 /libbb | |
parent | 4250ba3f536c66fa7caeb4e2a7110e69f69925de (diff) | |
download | busybox-w32-a0f78c266b49e283f862a642ede1cc1ed439162a.tar.gz busybox-w32-a0f78c266b49e283f862a642ede1cc1ed439162a.tar.bz2 busybox-w32-a0f78c266b49e283f862a642ede1cc1ed439162a.zip |
tee: fix bug: argv[-1] is a no-no!
bb_full_fd_action: optimize
die_if_ferror: "<applet>: filename" isn't a good err msg, add "..I/O error"
git-svn-id: svn://busybox.net/trunk/busybox@16669 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/copyfd.c | 47 | ||||
-rw-r--r-- | libbb/xfuncs.c | 4 |
2 files changed, 32 insertions, 19 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 601c51ce4..c6b886647 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -25,37 +25,50 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) | |||
25 | { | 25 | { |
26 | int status = -1; | 26 | int status = -1; |
27 | off_t total = 0; | 27 | off_t total = 0; |
28 | RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); | 28 | RESERVE_CONFIG_BUFFER(buffer, BUFSIZ); |
29 | 29 | ||
30 | if (src_fd < 0) goto out; | 30 | if (src_fd < 0) goto out; |
31 | while (!size || total < size) { | ||
32 | ssize_t wr, rd; | ||
33 | 31 | ||
34 | rd = safe_read(src_fd, buffer, | 32 | if (!size) { |
35 | (!size || size - total > BUFSIZ) ? BUFSIZ : size - total); | 33 | size = BUFSIZ; |
34 | status = 1; /* copy until eof */ | ||
35 | } | ||
36 | |||
37 | while (1) { | ||
38 | ssize_t rd; | ||
36 | 39 | ||
37 | if (rd > 0) { | 40 | rd = safe_read(src_fd, buffer, size > BUFSIZ ? BUFSIZ : size); |
38 | /* A -1 dst_fd means we need to fake it... */ | 41 | |
39 | wr = (dst_fd < 0) ? rd : full_write(dst_fd, buffer, rd); | 42 | if (!rd) { /* eof - all done. */ |
43 | status = 0; | ||
44 | break; | ||
45 | } | ||
46 | if (rd < 0) { | ||
47 | bb_perror_msg(bb_msg_read_error); | ||
48 | break; | ||
49 | } | ||
50 | /* dst_fd == -1 is a fake, else... */ | ||
51 | if (dst_fd >= 0) { | ||
52 | ssize_t wr = full_write(dst_fd, buffer, rd); | ||
40 | if (wr < rd) { | 53 | if (wr < rd) { |
41 | bb_perror_msg(bb_msg_write_error); | 54 | bb_perror_msg(bb_msg_write_error); |
42 | break; | 55 | break; |
43 | } | 56 | } |
44 | total += wr; | 57 | } |
45 | if (total == size) status = 0; | 58 | total += rd; |
46 | } else if (rd < 0) { | 59 | if (status < 0) { |
47 | bb_perror_msg(bb_msg_read_error); | 60 | size -= rd; |
48 | break; | 61 | if (!size) { |
49 | } else { /* eof - all done. */ | 62 | status = 0; |
50 | status = 0; | 63 | break; |
51 | break; | 64 | } |
52 | } | 65 | } |
53 | } | 66 | } |
54 | 67 | ||
55 | out: | 68 | out: |
56 | RELEASE_CONFIG_BUFFER(buffer); | 69 | RELEASE_CONFIG_BUFFER(buffer); |
57 | 70 | ||
58 | return status ? status : total; | 71 | return status ? -1 : total; |
59 | } | 72 | } |
60 | 73 | ||
61 | 74 | ||
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 1dbd7521b..773e718b8 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -124,7 +124,7 @@ int ndelay_on(int fd) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | // Die with an error message if we can't write the entire buffer. | 126 | // Die with an error message if we can't write the entire buffer. |
127 | void xwrite(int fd, void *buf, size_t count) | 127 | void xwrite(int fd, const void *buf, size_t count) |
128 | { | 128 | { |
129 | if (count) { | 129 | if (count) { |
130 | ssize_t size = full_write(fd, buf, count); | 130 | ssize_t size = full_write(fd, buf, count); |
@@ -146,7 +146,7 @@ off_t xlseek(int fd, off_t offset, int whence) | |||
146 | void die_if_ferror(FILE *fp, const char *fn) | 146 | void die_if_ferror(FILE *fp, const char *fn) |
147 | { | 147 | { |
148 | if (ferror(fp)) { | 148 | if (ferror(fp)) { |
149 | bb_error_msg_and_die("%s", fn); | 149 | bb_error_msg_and_die("%s: I/O error", fn); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||