Author: cem
Date: Thu Aug  2 23:45:14 2018
New Revision: 337203
URL: https://svnweb.freebsd.org/changeset/base/337203

Log:
  wc(1): Fix 'wc -L'
  
  I inadvertently broke 'wc -L' in r326736.  We must skip the fast path if -L
  was specified, in addition to the existing check for the -l option.
  
  Document long-standing -L behavior (count varies depending on whether wc(1)
  is run with the -m option or not) in wc.1.  That behavior dates back to the
  introduction of the -L option, but was not documented.
  
  PR:           230300
  Reported by:  <amstrnad+bugzilla AT gmail.com>
  Sponsored by: Dell EMC Isilon

Modified:
  head/usr.bin/wc/wc.1
  head/usr.bin/wc/wc.c

Modified: head/usr.bin/wc/wc.1
==============================================================================
--- head/usr.bin/wc/wc.1        Thu Aug  2 23:43:01 2018        (r337202)
+++ head/usr.bin/wc/wc.1        Thu Aug  2 23:45:14 2018        (r337203)
@@ -31,7 +31,7 @@
 .\"     @(#)wc.1       8.2 (Berkeley) 4/19/94
 .\" $FreeBSD$
 .\"
-.Dd December 1, 2015
+.Dd August 2, 2018
 .Dt WC 1
 .Os
 .Sh NAME
@@ -76,8 +76,11 @@ See
 .Xr xo_parse_args 3
 for details on command line arguments.
 .It Fl L
-The number of characters in the longest input line
-is written to the standard output.
+Write the length of the line containing the most bytes (default) or characters
+(when
+.Fl m
+is provided)
+to standard output.
 When more than one
 .Ar file
 argument is specified, the longest input line of

Modified: head/usr.bin/wc/wc.c
==============================================================================
--- head/usr.bin/wc/wc.c        Thu Aug  2 23:43:01 2018        (r337202)
+++ head/usr.bin/wc/wc.c        Thu Aug  2 23:45:14 2018        (r337203)
@@ -216,7 +216,7 @@ cnt(const char *file)
         * If all we need is the number of characters and it's a regular file,
         * just stat it.
         */
-       if (doline == 0) {
+       if (doline == 0 && dolongline == 0) {
                if (fstat(fd, &sb)) {
                        xo_warn("%s: fstat", file);
                        (void)close(fd);
@@ -246,7 +246,7 @@ cnt(const char *file)
                if (siginfo)
                        show_cnt(file, linect, wordct, charct, llct);
                charct += len;
-               if (doline) {
+               if (doline || dolongline) {
                        for (p = buf; len--; ++p)
                                if (*p == '\n') {
                                        if (tmpll > llct)
@@ -262,10 +262,8 @@ cnt(const char *file)
                tlinect += linect;
        if (dochar)
                tcharct += charct;
-       if (dolongline) {
-               if (llct > tlongline)
-                       tlongline = llct;
-       }
+       if (dolongline && llct > tlongline)
+               tlongline = llct;
        show_cnt(file, linect, wordct, charct, llct);
        (void)close(fd);
        return (0);
@@ -331,10 +329,8 @@ word:      gotsp = 1;
                twordct += wordct;
        if (dochar || domulti)
                tcharct += charct;
-       if (dolongline) {
-               if (llct > tlongline)
-                       tlongline = llct;
-       }
+       if (dolongline && llct > tlongline)
+               tlongline = llct;
        show_cnt(file, linect, wordct, charct, llct);
        (void)close(fd);
        return (0);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to