From 75aababed45d0120d44baa76c5107d0ceb71fc59 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 15 Feb 2017 15:58:08 -0800 Subject: maint: use xsetmode, not xfreopen This fixes a bug noted by Eric Blake. Code was using xfreopen to change files to binary mode, but this fails for stdout when in append mode. Such code should use xsetmode instead. This affects only the port on platforms like MS-Windows which distiguish text from binary I/O. * bootstrap.conf (gnulib_modules): Remove xfreopen and add xsetmode. Sort. * src/base64.c (main): * src/cat.c (main): * src/cksum.c (cksum): * src/head.c (head_file, main): * src/md5sum.c (digest_file): * src/od.c (open_next_file): * src/split.c (main): * src/sum.c (bsd_sum_file, sysv_sum_file): * src/tac.c (tac_file, main): * src/tail.c (tail_file): * src/tee.c (tee_files): * src/tr.c (main): * src/wc.c (wc_file): Use xsetmode, not xfreopen. --- src/tee.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/tee.c') diff --git a/src/tee.c b/src/tee.c index 74477cb7e..5f04bfc86 100644 --- a/src/tee.c +++ b/src/tee.c @@ -27,7 +27,7 @@ #include "error.h" #include "fadvise.h" #include "stdio--.h" -#include "xfreopen.h" +#include "xsetmode.h" /* The official name of this program (e.g., no 'g' prefix). */ #define PROGRAM_NAME "tee" @@ -194,11 +194,8 @@ tee_files (int nfiles, char **files) ? (append ? "ab" : "wb") : (append ? "a" : "w")); - if (O_BINARY && ! isatty (STDIN_FILENO)) - xfreopen (NULL, "rb", stdin); - if (O_BINARY && ! isatty (STDOUT_FILENO)) - xfreopen (NULL, "wb", stdout); - + xsetmode (STDIN_FILENO, O_BINARY); + xsetmode (STDOUT_FILENO, O_BINARY); fadvise (stdin, FADVISE_SEQUENTIAL); /* Set up FILES[0 .. NFILES] and DESCRIPTORS[0 .. NFILES]. -- cgit v1.2.3-54-g00ecf