From 556cdce5c8a92c0fbb1d6d829edb28299b43c6e8 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 6 May 1994 15:28:01 +0000 Subject: [PATCH] . --- src/tail.c | 3 ++- src/wc.c | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/tail.c b/src/tail.c index fd42a71532..727084ebad 100644 --- a/src/tail.c +++ b/src/tail.c @@ -968,7 +968,8 @@ tail_forever (names, nfiles) then keep looping. */ if (i != last) { - write_header (names[i]); + if (print_headers) + write_header (names[i]); last = i; } changed = 1; diff --git a/src/wc.c b/src/wc.c index 6480c7872a..904efe5c90 100644 --- a/src/wc.c +++ b/src/wc.c @@ -214,10 +214,28 @@ wc (fd, file) lines = words = chars = 0; - if (print_chars && !print_words && !print_lines - && fstat (fd, &stats) == 0 && S_ISREG (stats.st_mode)) + /* When counting only bytes, save some line- and word-counting + overhead. If FD is a `regular' Unix file, using fstat is enough + to get its size in bytes. Otherwise, read blocks of BUFFER_SIZE + bytes at a time until EOF. */ + if (print_chars && !print_words && !print_lines) { - chars = stats.st_size; + if (fstat (fd, &stats) == 0 && S_ISREG (stats.st_mode)) + { + chars = stats.st_size; + } + else + { + while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0) + { + chars += bytes_read; + } + if (bytes_read < 0) + { + error (0, errno, "%s", file); + exit_status = 1; + } + } } else { -- 2.47.3