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
This commit is contained in:
Ricardo Branco 2024-02-02 17:05:05 -07:00 committed by Warner Losh
parent 5ff76402da
commit 8e05c2373e

View file

@ -230,7 +230,8 @@ cnt(const char *file)
(void)close(fd);
return (1);
}
if (S_ISREG(sb.st_mode)) {
/* pseudo-filesystems advertize a zero size */
if (S_ISREG(sb.st_mode) && sb.st_size > 0) {
reset_siginfo();
charct = sb.st_size;
show_cnt(file, linect, wordct, charct, llct);