summaryrefslogtreecommitdiff
path: root/coreutils/tee.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2004-05-26 15:21:19 +0000
committerManuel Novoa III <mjn3@codepoet.org>2004-05-26 15:21:19 +0000
commitd709743b09a456f4550ad0b06dca89dc41a19e60 (patch)
tree994819fb891500254f5b5780c384b7cc075c9610 /coreutils/tee.c
parenta6f6a95ba45e094bbee6fd0895925a992e4a29cd (diff)
downloadbusybox-w32-d709743b09a456f4550ad0b06dca89dc41a19e60.tar.gz
busybox-w32-d709743b09a456f4550ad0b06dca89dc41a19e60.tar.bz2
busybox-w32-d709743b09a456f4550ad0b06dca89dc41a19e60.zip
If read were to return with an error, bad things would happen. Fix it.
Also, make sure read errors are reflected in the applet exit code.
Diffstat (limited to 'coreutils/tee.c')
-rw-r--r--coreutils/tee.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 6ec1d6dff..ba2e10f90 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -38,7 +38,7 @@ int tee_main(int argc, char **argv)
38 int flags; 38 int flags;
39 int retval = EXIT_SUCCESS; 39 int retval = EXIT_SUCCESS;
40#ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO 40#ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO
41 size_t c; 41 ssize_t c;
42 RESERVE_CONFIG_BUFFER(buf, BUFSIZ); 42 RESERVE_CONFIG_BUFFER(buf, BUFSIZ);
43#else 43#else
44 int c; 44 int c;
@@ -78,12 +78,16 @@ int tee_main(int argc, char **argv)
78 *p = NULL; /* Store the sentinal value. */ 78 *p = NULL; /* Store the sentinal value. */
79 79
80#ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO 80#ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO
81 while ((c = read(STDIN_FILENO, buf, BUFSIZ)) != 0) { 81 while ((c = safe_read(STDIN_FILENO, buf, BUFSIZ)) > 0) {
82 for (p=files ; *p ; p++) { 82 for (p=files ; *p ; p++) {
83 fwrite(buf, 1, c, *p); 83 fwrite(buf, 1, c, *p);
84 } 84 }
85 } 85 }
86 86
87 if (c < 0) { /* Make sure read errors are signaled. */
88 retval = EXIT_FAILURE;
89 }
90
87#ifdef CONFIG_FEATURE_CLEAN_UP 91#ifdef CONFIG_FEATURE_CLEAN_UP
88 RELEASE_CONFIG_BUFFER(buf); 92 RELEASE_CONFIG_BUFFER(buf);
89#endif 93#endif