summaryrefslogtreecommitdiff
path: root/src/tr.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-02-15 15:58:08 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-02-15 15:59:16 -0800
commit75aababed45d0120d44baa76c5107d0ceb71fc59 (patch)
tree5b4d628544b8640e489e356d881ff72ad6ff4db1 /src/tr.c
parente5cfadd6c7fa08153e56b950e72801677f7d1fe8 (diff)
downloadcoreutils-75aababed45d0120d44baa76c5107d0ceb71fc59.tar.xz
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.
Diffstat (limited to 'src/tr.c')
-rw-r--r--src/tr.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/tr.c b/src/tr.c
index bb86a8939..724297c9b 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -29,7 +29,7 @@
#include "fadvise.h"
#include "quote.h"
#include "safe-read.h"
-#include "xfreopen.h"
+#include "xsetmode.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no 'g' prefix). */
@@ -1786,11 +1786,8 @@ main (int argc, char **argv)
/* Use binary I/O, since 'tr' is sometimes used to transliterate
non-printable characters, or characters which are stripped away
by text-mode reads (like CR and ^Z). */
- 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);
if (squeeze_repeats && non_option_args == 1)