diff --git a/NEWS b/NEWS index da733cbd1..a3239537e 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 a6285ba0b..77bfc66bb 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 0f85e6476..a84cb8d7a 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_