From: Paul Eggert Date: Sat, 28 Feb 2026 00:17:27 +0000 (-0800) Subject: id: avoid unnecessary buffer flushing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d41e1375cb38f49fad5dfcab0460b2e702964d56;p=thirdparty%2Fcoreutils.git id: avoid unnecessary buffer flushing * src/groups.c (main): * src/id.c (main, print_stuff): Don’t flush stdout before testing for write error. Do the test only when in a loop, as a one-shot will test for write error soon anyway. --- diff --git a/NEWS b/NEWS index 473b7c21d8..7d46a5bcef 100644 --- a/NEWS +++ b/NEWS @@ -22,7 +22,7 @@ GNU coreutils NEWS -*- outline -*- ** Improvements - 'groups' and 'id' will now exit immediately upon receiving a write error, + 'groups' and 'id' will now exit sooner after a write error, which is significant when listing information for many users. 'nl' now supports multi-byte --section-delimiter characters. diff --git a/src/groups.c b/src/groups.c index 3daf410d9f..57acd376bc 100644 --- a/src/groups.c +++ b/src/groups.c @@ -135,7 +135,7 @@ main (int argc, char **argv) ok = false; putchar ('\n'); - if (fflush (stdout) < 0) + if (ferror (stdout)) write_error (); } } diff --git a/src/id.c b/src/id.c index 02c3bf9b50..27b3e8b708 100644 --- a/src/id.c +++ b/src/id.c @@ -277,6 +277,8 @@ main (int argc, char **argv) ruid = euid = pwd->pw_uid; rgid = egid = pwd->pw_gid; print_stuff (pw_name); + if (ferror (stdout)) + write_error (); } free (pw_name); } @@ -458,7 +460,4 @@ print_stuff (char const *pw_name) { putchar (opt_zero ? '\0' : '\n'); } - - if (fflush (stdout) < 0) - write_error (); }