aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/wc
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-08-02 23:45:14 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-08-02 23:45:14 +0000
commit84b851c23fecf26c88f1407b8a06282785c6bffd (patch)
treecbcb9a76d29af7ad656e35f99d8811e7c22a390d /usr.bin/wc
parent050b16aea8bb014827936006e350012319e431ad (diff)
downloadsrc-84b851c23fecf26c88f1407b8a06282785c6bffd.tar.gz
src-84b851c23fecf26c88f1407b8a06282785c6bffd.zip
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
Notes
Notes: svn path=/head/; revision=337203
Diffstat (limited to 'usr.bin/wc')
-rw-r--r--usr.bin/wc/wc.19
-rw-r--r--usr.bin/wc/wc.c16
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);