From: Paul Eggert Date: Mon, 11 Jul 2005 18:26:28 +0000 (+0000) Subject: (tail_bytes, tail_lines, tail_file, main): X-Git-Tag: CPPI-1_12~266 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9839325ad52f805c3c83d34241ce2d70a108dd6e;p=thirdparty%2Fcoreutils.git (tail_bytes, tail_lines, tail_file, main): Avoid setmode; use POSIX-specified routines instead. --- diff --git a/src/tail.c b/src/tail.c index f78f6f4797..cb2b1b7f00 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1127,10 +1127,6 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes, { struct stat stats; - /* We need binary input, since `tail' relies on `lseek' and byte counts, - while binary output will preserve the style (Unix/DOS) of text file. */ - SET_BINARY2 (fd, STDOUT_FILENO); - if (fstat (fd, &stats)) { error (0, errno, _("cannot fstat %s"), quote (pretty_filename)); @@ -1197,10 +1193,6 @@ tail_lines (const char *pretty_filename, int fd, uintmax_t n_lines, { struct stat stats; - /* We need binary input, since `tail' relies on `lseek' and byte counts, - while binary output will preserve the style (Unix/DOS) of text file. */ - SET_BINARY2 (fd, STDOUT_FILENO); - if (fstat (fd, &stats)) { error (0, errno, _("cannot fstat %s"), quote (pretty_filename)); @@ -1283,9 +1275,11 @@ tail_file (struct File_spec *f, uintmax_t n_units) { have_read_stdin = true; fd = STDIN_FILENO; + if (O_BINARY && ! isatty (STDIN_FILENO)) + freopen (NULL, "rb", stdin); } else - fd = open (f->name, O_RDONLY); + fd = open (f->name, O_RDONLY | O_BINARY); f->tailable = !(reopen_inaccessible_files && fd == -1); @@ -1675,6 +1669,9 @@ main (int argc, char **argv) || (header_mode == multiple_files && n_files > 1)) print_headers = true; + if (O_BINARY && ! isatty (STDOUT_FILENO)) + freopen (NULL, "wb", stdout); + for (i = 0; i < n_files; i++) ok &= tail_file (&F[i], n_units);