diff options
author | Jim Meyering <jim@meyering.net> | 1994-05-06 15:28:01 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1994-05-06 15:28:01 +0000 |
commit | 556cdce5c8a92c0fbb1d6d829edb28299b43c6e8 (patch) | |
tree | 101f01a0dcb280dc45514da8649395c11da3323e /src | |
parent | 31185771208980da2c1c5924a960538b158880a6 (diff) | |
download | coreutils-556cdce5c8a92c0fbb1d6d829edb28299b43c6e8.tar.xz |
.
Diffstat (limited to 'src')
-rw-r--r-- | src/tail.c | 3 | ||||
-rw-r--r-- | src/wc.c | 24 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/tail.c b/src/tail.c index fd42a7153..727084eba 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; @@ -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 { |