summaryrefslogtreecommitdiff
path: root/src/tee.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-07-11 18:26:52 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-07-11 18:26:52 +0000
commita1170668ff7ff2f348f801b086fb2561dadeb226 (patch)
tree18aa2b0ba601efd8cf3180c207e394277aa22040 /src/tee.c
parent9839325ad52f805c3c83d34241ce2d70a108dd6e (diff)
downloadcoreutils-a1170668ff7ff2f348f801b086fb2561dadeb226.tar.xz
(tee): Avoid setmode; use POSIX-specified routines instead.
Diffstat (limited to 'src/tee.c')
-rw-r--r--src/tee.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/tee.c b/src/tee.c
index fa971b37b..f99642db4 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -140,7 +140,10 @@ tee (int nfiles, const char **files)
ssize_t bytes_read;
int i;
bool ok = true;
- const char *mode_string = (append ? "a" : "w");
+ char const *mode_string =
+ (O_BINARY
+ ? (append ? "ab" : "wb")
+ : (append ? "a" : "w"));
descriptors = xnmalloc (nfiles + 1, sizeof *descriptors);
@@ -149,7 +152,10 @@ tee (int nfiles, const char **files)
for (i = nfiles; i >= 1; i--)
files[i] = files[i - 1];
- SET_BINARY2 (0, 1);
+ if (O_BINARY && ! isatty (STDIN_FILENO))
+ freopen (NULL, "rb", stdin);
+ if (O_BINARY && ! isatty (STDOUT_FILENO))
+ freopen (NULL, "wb", stdout);
/* In the array of NFILES + 1 descriptors, make
the first one correspond to standard output. */
@@ -168,10 +174,7 @@ tee (int nfiles, const char **files)
ok = false;
}
else
- {
- SETVBUF (descriptors[i], NULL, _IONBF, 0);
- SET_BINARY (fileno (descriptors[i]));
- }
+ SETVBUF (descriptors[i], NULL, _IONBF, 0);
}
while (1)