]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
.
authorJim Meyering <jim@meyering.net>
Fri, 6 May 1994 15:28:01 +0000 (15:28 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 6 May 1994 15:28:01 +0000 (15:28 +0000)
src/tail.c
src/wc.c

index fd42a71532b69ab1141b2e8623a2e34c4e4c6e42..727084ebad3938220c88122b795221583da06785 100644 (file)
@@ -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;
index 6480c7872a9faa5994fe9a666b89045b242ab625..904efe5c902f0d8e9552f37b546f8ea27cb817c6 100644 (file)
--- 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
     {