]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pr: promptly diagnose write errors
authorPádraig Brady <P@draigBrady.com>
Wed, 22 Oct 2025 17:13:48 +0000 (18:13 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 22 Oct 2025 18:11:37 +0000 (19:11 +0100)
* src/pr.c (print_page): Exit promptly for `yes | pr`.
(print_clump): Exit promptly for `pr < /dev/zero`.
* tests/misc/write-errors.sh: Enable test cases.
* NEWS: Mention the improvement.

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

diff --git a/NEWS b/NEWS
index fb3359fd4deb02e3069af6c4b462a85c7582f214..a5471f37567d495b990c12fd882e2f1d1d00f3f6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -43,7 +43,7 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Improvements
 
-  'fmt' and 'nl' will now exit promptly upon receiving a write error,
+  'fmt', 'nl', and 'pr' 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 87974d058b7bad25bbf156c300ca2068e3997de1..440efac0af3bac0ad62548b1e732ee20136e2683 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1886,6 +1886,9 @@ print_page (void)
       print_a_FF = false;
     }
 
+  if (ferror (stdout))
+    write_error ();
+
   if (last_page_number < ++page_number)
     return false;              /* Stop printing with LAST_PAGE */
 
@@ -2286,6 +2289,9 @@ print_clump (COLUMN *p, int n, char *clump)
 {
   while (n--)
     (p->char_func) (*clump++);
+
+  if (ferror (stdout))
+    write_error ();
 }
 
 /* Print a character.
index 77f7fc860b8385a7b07f5c4dd94f3162cfa797c9..b33e84a3d6f6b1840b48027ede4c5771afa2234c 100755 (executable)
@@ -45,7 +45,8 @@ nl --version; yes | nl
 numfmt --version; yes 1 | numfmt
 od -v /dev/zero
 paste /dev/zero
-# TODO: pr /dev/zero
+pr /dev/zero
+pr --version; yes 1 | pr
 seq inf
 tail -n+1 -z /dev/zero
 tee < /dev/zero