summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-07-11 18:26:28 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-07-11 18:26:28 +0000
commit9839325ad52f805c3c83d34241ce2d70a108dd6e (patch)
tree2fd1f00ec88aa0d50d68428e9505ff00906ce109 /src/tail.c
parentb91eec6bb2489c5c3c5eb2644a043cc6d8f3a587 (diff)
downloadcoreutils-9839325ad52f805c3c83d34241ce2d70a108dd6e.tar.xz
(tail_bytes, tail_lines, tail_file, main):
Avoid setmode; use POSIX-specified routines instead.
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/tail.c b/src/tail.c
index f78f6f479..cb2b1b7f0 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);