From: Pádraig Brady
Date: Wed, 22 Oct 2025 15:31:15 +0000 (+0100) Subject: nl: promptly diagnose write errors X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9415cf01c639788e414f63f7ae5e0231844df6d8;p=thirdparty%2Fcoreutils.git nl: promptly diagnose write errors * NEWS: Mention the improvement. * src/nl.c (process_file): Exit if error outputting line. * tests/misc/write-errors.sh: Enable the test case. --- diff --git a/NEWS b/NEWS index 55fe59503e..fb3359fd4d 100644 --- 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. diff --git a/src/nl.c b/src/nl.c index f243a29536..7060751621 100644 --- a/src/nl.c +++ b/src/nl.c @@ -425,6 +425,9 @@ process_file (FILE *fp) proc_text (); break; } + + if (ferror (stdout)) + write_error (); } } diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index 48f9c0f1a8..77f7fc860b 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -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