History log of /openbsd-src/usr.bin/wc/wc.c (Results 1 – 25 of 32)
Revision Date Author Comments
# e291b8af 11-Sep-2024 guenther <guenther@openbsd.org>

fstat(2) can't return an S_IFLNK, so delete that test.
Also, switch to S_IS*() tests and update the manpage
to reflect that POSIX-2024 has no substantive changes
for wc(1)

ok op@ millert@


# d7259957 04-Dec-2022 cheloha <cheloha@openbsd.org>

userspace: remove vestigial '?' cases from top-level getopt(3) loops

getopt(3) returns '?' when it encounters a flag not present in the in
the optstring or if a flag is missing its option argument.

userspace: remove vestigial '?' cases from top-level getopt(3) loops

getopt(3) returns '?' when it encounters a flag not present in the in
the optstring or if a flag is missing its option argument. We can
handle this case with the "default" failure case with no loss of
legibility. Hence, remove all the redundant "case '?':" lines.

Prompted by dlg@. With help from dlg@ and millert@.

Link: https://marc.info/?l=openbsd-tech&m=167011979726449&w=2

ok naddy@ millert@ dlg@

show more ...


# 3a7fc93e 02-Sep-2022 cheloha <cheloha@openbsd.org>

wc(1): accelerate word counting

wc(1) counts a word whenever a whitespace byte is followed by a
non-whitespace byte. Because the state machine transition occurs
within the space of a single byte we

wc(1): accelerate word counting

wc(1) counts a word whenever a whitespace byte is followed by a
non-whitespace byte. Because the state machine transition occurs
within the space of a single byte we don't need to use getline(3).

Counting words in a big buffer with read(2) is much faster. The
overhead varies with the length of a line, but for files with 60-100
byte lines, word counting is about twice as fast when we avoid
getline(3). In the pathological case where each line is a single
byte, word counting is about ten times as fast when we avoid
getline(3).

Link1: https://marc.info/?l=openbsd-tech&m=163715995626532&w=2
Link2: https://marc.info/?l=openbsd-tech&m=165956826103639&w=2

"Seems reasonable." deraadt@

show more ...


# 1a0afcde 28-Nov-2021 deraadt <deraadt@openbsd.org>

Stop using MAXBSIZE to eliminate sys/param.h including (which injects a
ton of namespace intrusion). Create local sizes, and refactor some code
along the way.
ok millert


# cca9d5ee 16-Nov-2021 cheloha <cheloha@openbsd.org>

wc(1): fix NULL pointer dereference in cnt()

If the "file" argument to cnt() is NULL and we call warn(3) we will
get a NULL dereference.

Change the name of the argument to "path" and make "file" a

wc(1): fix NULL pointer dereference in cnt()

If the "file" argument to cnt() is NULL and we call warn(3) we will
get a NULL dereference.

Change the name of the argument to "path" and make "file" a local
variable. Ensure that we set "file" to a valid C-string, even if
"path" is NULL.

While we're here, const the file name pointers, too.

Thread: https://marc.info/?l=openbsd-tech&m=163708784422157&w=2

ok millert@

show more ...


# b7041c07 24-Oct-2021 deraadt <deraadt@openbsd.org>

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which mig

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert

show more ...


# 3aaa63eb 28-Jun-2019 deraadt <deraadt@openbsd.org>

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.

show more ...


# fdee8386 30-Sep-2018 schwarze <schwarze@openbsd.org>

For -w output in -m mode, tweak the handling of bytes that do not
form valid UTF-8: treat them as "not a whitespace character" and
hence "not a word boundary" in the same way as non-printable
charact

For -w output in -m mode, tweak the handling of bytes that do not
form valid UTF-8: treat them as "not a whitespace character" and
hence "not a word boundary" in the same way as non-printable
characters and NUL bytes.

OK millert@

show more ...


# 44dfd84e 30-Sep-2018 schwarze <schwarze@openbsd.org>

fix the rest of the bug mitigated in the previous commit:
do not embark on an infinite loop
when -m is given and the file contains a NUL character;
OK millert@


# db2f9856 29-Sep-2018 cheloha <cheloha@openbsd.org>

Treat NUL like any other byte in the default case; aligns newline count
with that of the '-l' case.

From David Hines on bugs@.

ok millert@


# f4147939 26-Apr-2018 guenther <guenther@openbsd.org>

Use <fcntl.h> instead of <sys/file.h> for open() and friends.
Delete a bunch of unnecessary #includes and sort to match style(9)
while doing the above cleanup.

ok deraadt@ krw@


# 9d9861e5 16-Sep-2016 fcambus <fcambus@openbsd.org>

- Removed unnecessary string.h include
- Changed 'format_and_print' argument type to int64_t and casting
inside the function
- Declaring 'print_counts', 'format_and_print', and 'cnt' as static
- Re

- Removed unnecessary string.h include
- Changed 'format_and_print' argument type to int64_t and casting
inside the function
- Declaring 'print_counts', 'format_and_print', and 'cnt' as static
- Remove unnecessary cast for NULL, and (void) casts from printfs,
'mbtowc' and 'format_and_print' calls
- In 'cnt', change bufsz type from ssize_t to size_t to avoid
converting between pointers to integer types with different sign
when calling getline (catched when compiling with Clang)
- Use return instead of exit in main

OK jung@

show more ...


# af00b5ca 08-Dec-2015 schwarze <schwarze@openbsd.org>

UTF-8 support: implement -m for character counting
and use iswspace(3) for word counting.
Requires using getline(3) rather than read(2)
to make sure that characters aren't chopped to pieces.

Using f

UTF-8 support: implement -m for character counting
and use iswspace(3) for word counting.
Requires using getline(3) rather than read(2)
to make sure that characters aren't chopped to pieces.

Using feedback from millert@ on an earlier version.
Feedback and OK tedu@.

show more ...


# 0bd1216c 09-Oct-2015 deraadt <deraadt@openbsd.org>

Change all tame callers to namechange to pledge(2).


# 3f60ec37 03-Oct-2015 deraadt <deraadt@openbsd.org>

wc only opens files read-only, proceses them, and spits results to stdout.
tame "stdio rpath" works, right before calling getopt()


# b9fc9a72 16-Jan-2015 deraadt <deraadt@openbsd.org>

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_N

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)

show more ...


# 5195d91e 27-Nov-2013 okan <okan@openbsd.org>

remove erroneous char cast to switch expression processing getopt(3);
not used in any cases.

ok deraadt@, guenther@, millert@


# 125129e8 23-Nov-2013 deraadt <deraadt@openbsd.org>

send a extra space to the bit bucket


# 43a6699f 12-Nov-2013 deraadt <deraadt@openbsd.org>

simpler prototype repairs


# 043fbe51 27-Oct-2009 deraadt <deraadt@openbsd.org>

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(th

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms

show more ...


# 170cb279 19-Jun-2008 otto <otto@openbsd.org>

do not print spurious whitespace when reading from stdin;
from Bernd Ahlers with a twist from me; ok millert@


# c93d6c49 19-Oct-2005 espie <espie@openbsd.org>

Add -h option to display human-readable numbers.

okay otto@, deraadt@, jmc@.

(note that is mostly useless from scripts, hence okay as a non-standard
option).


# 96de7668 11-Apr-2005 deraadt <deraadt@openbsd.org>

spacing


# f75387cb 03-Jun-2003 millert <millert@openbsd.org>

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# dad987f9 17-Sep-2002 deraadt <deraadt@openbsd.org>

ansi


12