From: Pádraig Brady Date: Wed, 22 Oct 2025 17:13:48 +0000 (+0100) Subject: pr: promptly diagnose write errors X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5b147fabfa7bb99a0f940ed84c65233554db55d;p=thirdparty%2Fcoreutils.git 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. --- 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