From 2b9bca3e0821d506e45f69dc7a746b2b5635678b Mon Sep 17 00:00:00 2001 From: cem Date: Thu, 2 Aug 2018 23:45:14 +0000 Subject: [PATCH] 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: Sponsored by: Dell EMC Isilon --- usr.bin/wc/wc.1 | 9 ++++++--- usr.bin/wc/wc.c | 16 ++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/usr.bin/wc/wc.1 b/usr.bin/wc/wc.1 index 63cbe4ccfb76..c31bb865385e 100644 --- a/usr.bin/wc/wc.1 +++ b/usr.bin/wc/wc.1 @@ -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 diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index 67d6f51092d4..c2990035c0c7 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -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);