From: Pádraig Brady Date: Fri, 9 Jan 2026 14:16:04 +0000 (+0000) Subject: wc: promptly diagnose write errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83f274feaa84f709a8da7b137ec0353e87c4a4c8;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/NEWS b/NEWS index da733cbd15..a3239537e4 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/src/wc.c b/src/wc.c index a6285ba0be..77bfc66bb5 100644 --- a/src/wc.c +++ b/src/wc.c @@ -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. */ diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index 0f85e6476b..a84cb8d7a0 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -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_