]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
wc: promptly diagnose write errors
authorPádraig Brady <P@draigBrady.com>
Fri, 9 Jan 2026 14:16:04 +0000 (14:16 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 10 Jan 2026 01:04:33 +0000 (01:04 +0000)
* 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.

NEWS
src/wc.c
tests/misc/write-errors.sh

diff --git a/NEWS b/NEWS
index da733cbd15efdd895725b6aa361c052c1c2ef624..a3239537e456febb554c8941851ee50cfb70e582 100644 (file)
--- 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
index a6285ba0bedc42a3a2ef0869c15a570a53c1347b..77bfc66bb536e10285c7c8d2e85cdb4bb1dbd901 100644 (file)
--- 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.  */
index 0f85e6476b75e96958d20646cdfcc696f2afd974..a84cb8d7a08a68397900e8bd843eeb67088a30f9 100755 (executable)
@@ -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_