From c5b147fabfa7bb99a0f940ed84c65233554db55d Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Wed, 22 Oct 2025 18:13:48 +0100 Subject: [PATCH] pr: promptly diagnose write errors * 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 | 2 +- src/pr.c | 6 ++++++ tests/misc/write-errors.sh | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index fb3359fd4d..a5471f3756 100644 --- 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. diff --git a/src/pr.c b/src/pr.c index 87974d058b..440efac0af 100644 --- 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. diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index 77f7fc860b..b33e84a3d6 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -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 -- 2.47.3