diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-07-11 18:25:56 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-07-11 18:25:56 +0000 |
commit | b91eec6bb2489c5c3c5eb2644a043cc6d8f3a587 (patch) | |
tree | 34a5a083cd5ae228dd63026b6a3142d5557e5adf /src/tac.c | |
parent | ed0dda33d553bfd17338d4bd9ccd6a8bd61489bd (diff) | |
download | coreutils-b91eec6bb2489c5c3c5eb2644a043cc6d8f3a587.tar.xz |
(copy_to_temp, tac_file, main):
Avoid setmode; use POSIX-specified routines instead.
Diffstat (limited to 'src/tac.c')
-rw-r--r-- | src/tac.c | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -455,7 +455,7 @@ copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file) return false; } - tmp = fdopen (fd, "w+"); + tmp = fdopen (fd, (O_BINARY ? "w+b" : "w+")); if (! tmp) { error (0, errno, _("cannot open %s for writing"), quote (tempfile)); @@ -490,7 +490,6 @@ copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file) goto Fail; } - SET_BINARY (fileno (tmp)); *g_tmp = tmp; *g_tempfile = tempfile; return true; @@ -529,10 +528,12 @@ tac_file (const char *filename) have_read_stdin = true; fd = STDIN_FILENO; filename = _("standard input"); + if (O_BINARY && ! isatty (STDIN_FILENO)) + freopen (NULL, "rb", stdin); } else { - fd = open (filename, O_RDONLY); + fd = open (filename, O_RDONLY | O_BINARY); if (fd < 0) { error (0, errno, _("cannot open %s for reading"), quote (filename)); @@ -540,16 +541,6 @@ tac_file (const char *filename) } } - /* We need binary I/O, since `tac' relies - on `lseek' and byte counts. - - Binary output will leave the lines' ends (NL or - CR/LF) intact when the output is a disk file. - Writing a file with CR/LF pairs at end of lines in - text mode has no visible effect on console output, - since two CRs in a row are just like one CR. */ - SET_BINARY2 (fd, STDOUT_FILENO); - file_size = lseek (fd, (off_t) 0, SEEK_END); ok = (0 <= file_size @@ -651,6 +642,9 @@ main (int argc, char **argv) ? (char const *const *) &argv[optind] : default_file_list); + if (O_BINARY && ! isatty (STDOUT_FILENO)) + freopen (NULL, "wb", stdout); + { size_t i; ok = true; |