]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nl: promptly diagnose write errors
authorPádraig Brady <P@draigBrady.com>
Wed, 22 Oct 2025 15:31:15 +0000 (16:31 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 22 Oct 2025 15:32:34 +0000 (16:32 +0100)
* NEWS: Mention the improvement.
* src/nl.c (process_file): Exit if error outputting line.
* tests/misc/write-errors.sh: Enable the test case.

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

diff --git a/NEWS b/NEWS
index 55fe59503eb18ac30a36192279a0e5f5ed4bc404..fb3359fd4deb02e3069af6c4b462a85c7582f214 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -43,7 +43,7 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Improvements
 
-  'fmt' will now exit promptly upon receiving a write error,
+  'fmt' and 'nl' will now exit promptly upon receiving a write error,
   which is significant when reading large / unbounded inputs.
 
   'install' now uses posix_spawn() to invoke the strip program more efficiently.
index f243a295360f2b8ddfbffff93ca6c253f5242953..70607516214bae593c96b7034aeddc3dc2a96ecd 100644 (file)
--- a/src/nl.c
+++ b/src/nl.c
@@ -425,6 +425,9 @@ process_file (FILE *fp)
           proc_text ();
           break;
         }
+
+      if (ferror (stdout))
+        write_error ();
     }
 }
 
index 48f9c0f1a8417378dbf767aaee00735dda03b7ab..77f7fc860b8385a7b07f5c4dd94f3162cfa797c9 100755 (executable)
@@ -41,7 +41,7 @@ fold -c /dev/zero
 fold --version; yes | tr -d '\\n' | fold
 head -z -n-1 /dev/zero
 join -a 1 -z /dev/zero /dev/null
-# TODO: nl --version; yes | nl
+nl --version; yes | nl
 numfmt --version; yes 1 | numfmt
 od -v /dev/zero
 paste /dev/zero