History log of /freebsd-current/usr.bin/wc/wc.c
Revision Date Author Comments
# d0bf8b5a 18-Feb-2024 Bryan Drewery <bdrewery@FreeBSD.org>

wc: Fix SIGINFO race with casper init.

If a file is specified then fileargs_init(3) may return [EINTR]. With
the SIGINFO handler not being SA_RESTART this causes an early exit
if a SIGINFO comes in. Rather than checking for [EINTR] or changing the
handler just move it later which resolves the problem.


# 8e05c237 02-Feb-2024 Ricardo Branco <rbranco@suse.de>

wc: Do not use st_size if it equals zero

Pseudo-filesystems often cannot compute the size of the file correctly
and report 0 for the size. Ignore the size when it's zero and fallback
to the size unknown code.

PR: 276093
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/985


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 5016d112 15-Feb-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

wc: Make the read buffer static.

The read buffer in cnt() is 64 kB, which is a bit excessive for a stack variable. MAXBSIZE has grown since this code was originally written, and it might grow again in the future. Since the program is single-threaded and cnt() does not recurse, we can safely make the buffer static.

While there, constify p since it is only used to read.

Sponsored by: Klara, Inc.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D38608


# dad64f0e 14-Feb-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

wc: Clean up and modernize.

* Drop <err.h>, which is unnecessary since we use libxo.

* As per POSIX, report an error if output fails.

* Fix some type mismatches.

* Use bool instead of int where appropriate.

* Avoid repeatedly checking for a null filename.

* Miscellaneous other tidying.

* Add tests (partly derived from work performed by SHENG-YI HONG <i19780219111@kimo.com>).

Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D38496


# fbdf4758 05-Feb-2020 Kyle Evans <kevans@FreeBSD.org>

wc(1): account for possibility of file == NULL

file could reasonably be NULL here if we we're using stdin. Albeit less
likely in normal usage, one could actually hit either of these warnings on
stdin.

ubmitted by: sigsys@gmail.com
MFC after: 3 days


# d76eef34 17-Apr-2019 Ed Maste <emaste@FreeBSD.org>

cap_fileargs: chase r346315, update fileargs_init in consumers

Reported by: ci.freebsd.org (8 times so far)
MFC after: 3 weeks
MFC with: r346315
Sponsored by: The FreeBSD Foundation


# 509e73d4 12-Nov-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

s/caph_enter_capser/caph_enter_casper/g

Reported by: npn


# 8e4febf0 12-Nov-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

s/caph_enter_with_casper/caph_enter_casper/

Reported by: npn


# c71292ea 12-Nov-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

wc: We should sandbox wc only if Capers is available.


# 9e4c5144 12-Nov-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

wc: sandbox wc using capsicum

Reviewed by: AllanJude, emaste
Differential Revision: https://reviews.freebsd.org/D14409


# 84b851c2 02-Aug-2018 Conrad Meyer <cem@FreeBSD.org>

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


# 0dc7c9e6 10-Dec-2017 Conrad Meyer <cem@FreeBSD.org>

wc(1): Restore regular file char count fast path

fstat(2) is going to be a lot faster than reading all of the bytes in a
file, if we just need a character count for a regular file. This fast path
was accidentally broken in r326736.

PR: 224160
Reported by: bde
Sponsored by: Dell EMC Isilon


# de143041 09-Dec-2017 Conrad Meyer <cem@FreeBSD.org>

wc(1): Extend non-controversial optimizations to '-c' mode

wc(1)'s slow path for counting words or multibyte characters requires
conversion of the 8-bit input stream to wide characters. However, a faster
path can be used for counting only lines ('-l' -- newlines have the same
representation in all supported encodings) or bytes ('-c').

The existing line count optimization was not used if the input was the
implicit stdin. Additionally, it wasn't used if only byte counting was
requested. This change expands the fast path to both of these scenarios.

Expanding the buffer size from 64 kB helps reduce the number of read(2)
calls needed, but exactly what impact that change has and what size to
expand the buffer to are still under discussion.

PR: 224160
Tested by: wosch (earlier version)
Sponsored by: Dell EMC Isilon


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 8ded906d 16-Apr-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Fix SIGINFO race causing final results to be lost to stderr.

If a SIGINFO comes in after the file is read then the 'siginfo' flag is set to
1 and the next call to show_cnt() (at exit) would print the data to stderr
rather than the expected stdout.

This was found with spamming Poudriere with SIGINFO which caused a 'wc -l'
execution to return no data rather than an expected number.

MFC after: 2 weeks


# 399d3485 11-Feb-2015 Marcel Moolenaar <marcel@FreeBSD.org>

Close the file list before opening the container that holds the
totals, otherwise we end up emitting invalid JSON -- provided
libxo does not prevent us from doing that.

PR: 197499
Submitted by: allanjude@


# 985c93f0 06-Nov-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Fix a SIGSEGV when emitting XML or JSON when reading stdin. In that
case the file variable is NULL.


# 6711c482 04-Nov-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Convert to use libxo.

Obtained from: Phil Shafer <phil@juniper.net>
Sponsored by: Juniper Networks, Inc.


# 8df975a2 06-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Add missing static keywords to wc(1)


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# c9a96406 17-May-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Use better type for siginfo (volatile sig_atomic_t instead of int).

Pointed out by: jh


# f09bc093 16-May-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>

On SIGINFO print current values on stderr.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 0970727f 29-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Add missing `void' keyword for function without arguments.


# f45dd010 06-Dec-2008 Giorgos Keramidas <keramida@FreeBSD.org>

Add a -L option to wc(1), for finger compatibility with the GNU
wc utility. The -L option can be used to report the length of
the longest line wc has seen in one or more files. It is
disabled by default, and wc uses the standard `-lwc'.

Submitted by: Sheldon Givens, sheldon at sigsegv.ca
Reviewed by: kib
MFC after: 1 week


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 806abfcc 27-Dec-2004 Josef El-Rayes <josef@FreeBSD.org>

Remove warnings and make wc WARNS=6 clean.
Add FreeBSD Id to Makefile.

Approved by: ssouhlal


# 149a123b 09-Apr-2004 Tim J. Robbins <tjr@FreeBSD.org>

Improve robustness of multibyte character handling (-m option), and
simplify the read buffering now that we can feed partial multibyte
characters to mbrtowc().


# e58245f7 11-Aug-2002 Tim J. Robbins <tjr@FreeBSD.org>

Use the iswspace(3) function now that it's been implemented.


# abd0c85d 16-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

When counting words, check the correct character variable to see whether it's
a space or not.

Noticed by: bde


# a1a27143 15-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

fstat() returns information about the target of any symbolic link that
was opened, not the link itself. Remove dead code.


# ebb42aee 12-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Add the -m option, which counts characters (as opposed to -c, which
counts bytes). In locales that don't have multibyte characters, -m
is effectively an alias for -c.

This brings wc(1) up to P1003.1-2001 conformance.


# 3f330d7d 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# 06469209 07-Mar-2002 Mike Barcroft <mike@FreeBSD.org>

Leave the `copyright' variable exposed, since the main purpose of it
is to put a copyright in the object file.

Submitted by: bde


# a821e36e 28-Feb-2002 Mike Barcroft <mike@FreeBSD.org>

Fix vendor ID (mostly obtained from rev 1.1).

Make use of `static' storage-class for local functions.

Replace uses of `u_quad_t' with `uintmax_t'.


# 7a8fb588 11-Dec-2001 Mark Murray <markm@FreeBSD.org>

WARNS=2 fix, use __FBSDID().

Not added to Makefgile as WARNS=2 will be made default.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# a0cf59e6 12-Aug-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Correct style issues with the previous commit.

Requested by: bde


# af86fc21 06-Aug-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Fix integer overflow for files containing more than 4GB by using
u_quad_int instead of u_long for counters. (NetBSD's rev 1.15 - 1.18)

Deprecate register. (NetBSD's rev 1.13)

The diffs from NetBSD were not applied verbatim, because we don't care
about NO_QUAD right now.

PR: 12959
Reported by: Nicholas Barnes <nb@ravenbrook.com>
Obtained from: NetBSD


# 8c85cce7 25-Aug-1997 Philippe Charnier <charnier@FreeBSD.org>

Sync usage string according to man page. Silent -Wall.


# c44252b6 06-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Finish importing Lite2's src/usr.bin, except for ex, diff, grep, mail,
pascal and vmstat.sparc. All changed files on the vendor branch should
already have been imported.


# 1c8af878 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# c115df18 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 2c51e5ed 13-Apr-1996 Bruce Evans <bde@FreeBSD.org>

Changed all per-file errors to warnings. Exit with a nonzero status of
if there was a per-file error. My test case of `wc /proc/curproc/*'
works reasonably now (much like `size /proc/curproc/*'.

Reviewed by: wosch


# a0d038a4 10-Apr-1996 Wolfram Schneider <wosch@FreeBSD.org>

Do not exit if a file is not readable. This is a short hack
until someone rewrite wc(1).


# ae6fa8ae 10-Jan-1996 Andrey A. Chernov <ache@FreeBSD.org>

Localize it.


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources