wc: promptly diagnose write errors

* src/wc.c (write_counts): Call write_error() if any pending errors.
* tests/misc/write-errors.sh: Add a test case.
* NEWS: Mention the improvement.
This commit is contained in:
Pádraig Brady 2026-01-09 14:16:04 +00:00
parent b34e329f75
commit 83f274feaa
3 changed files with 7 additions and 0 deletions

3
NEWS
View File

@ -88,6 +88,9 @@ GNU coreutils NEWS -*- outline -*-
'timeout' on Linux will always terminate the child in the case where the
timeout process itself dies, like when it receives a KILL signal for example.
'wc' now exits promptly upon receiving a write error,
which is significant when processing many input files.
** Build-related
'kill' and 'uptime' are no longer built by default. These programs can be

View File

@ -258,6 +258,9 @@ write_counts (uintmax_t lines,
if (file)
printf (" %s", strchr (file, '\n') ? quotef (file) : file);
putchar ('\n');
if (ferror (stdout))
write_error ();
}
/* Read FD and return a summary. */

View File

@ -56,6 +56,7 @@ tee < /dev/zero
tr . . < /dev/zero
unexpand /dev/zero
uniq -z -D /dev/zero
wc --version; yes /dev/null | tr '\\\\n' '\\\\0' | wc --files0-from=-
yes
" |
sort -k 1b,1 > all_writers || framework_failure_