]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(wc): Add a separate loop for counting only lines or lines and bytes.
authorJim Meyering <jim@meyering.net>
Thu, 9 Feb 1995 17:15:17 +0000 (17:15 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 9 Feb 1995 17:15:17 +0000 (17:15 +0000)
From Karl Heuer.

src/wc.c

index 34706ae675fc9b63ee1e1d169c231316d31d83cf..7dca0f37d93f19447c2d58459b2c91b804b5564c 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -238,6 +238,28 @@ wc (fd, file)
            }
        }
     }
+  else if (!print_words)
+    {
+      /* Use a separate loop when counting only lines or lines and bytes --
+        but not words.  */
+      while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
+       {
+         register char *p = buf;
+
+         chars += bytes_read;
+         do
+           {
+             if (*p++ == '\n')
+               lines++;
+           }
+         while (--bytes_read);
+       }
+      if (bytes_read < 0)
+       {
+         error (0, errno, "%s", file);
+         exit_status = 1;
+       }
+    }
   else
     {
       while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)