summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-09-22 16:00:49 +0000
committerJim Meyering <jim@meyering.net>2003-09-22 16:00:49 +0000
commit09203489dd8f128542032b6713eb5979463e1742 (patch)
tree95d941b702bf99aa41b60c772cb6e276330612ba
parent8a0be33fd7cf9b7e2a11ad4a0d093ee4c886ea80 (diff)
downloadcoreutils-09203489dd8f128542032b6713eb5979463e1742.tar.xz
(tee): Once a write failure has occurred, don't bother
writing anything more to that stream.
-rw-r--r--src/tee.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/tee.c b/src/tee.c
index a1eb4753d..a45e4bfde 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -209,10 +209,13 @@ tee (int nfiles, const char **files)
/* Write to all NFILES + 1 descriptors.
Standard output is the first one. */
for (i = 0; i <= nfiles; i++)
- {
- if (descriptors[i] != NULL)
- fwrite (buffer, bytes_read, 1, descriptors[i]);
- }
+ if (descriptors[i]
+ && fwrite (buffer, bytes_read, 1, descriptors[i]) != bytes_read)
+ {
+ error (0, errno, "%s", files[i]);
+ descriptors[i] = NULL;
+ ret = 1;
+ }
}
if (bytes_read == -1)
@@ -223,8 +226,7 @@ tee (int nfiles, const char **files)
/* Close the files, but not standard output. */
for (i = 1; i <= nfiles; i++)
- if (descriptors[i] != NULL
- && (ferror (descriptors[i]) || fclose (descriptors[i]) == EOF))
+ if (descriptors[i] && fclose (descriptors[i]) != 0)
{
error (0, errno, "%s", files[i]);
ret = 1;