]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
id: avoid unnecessary buffer flushing
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 28 Feb 2026 00:17:27 +0000 (16:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 28 Feb 2026 00:18:32 +0000 (16:18 -0800)
* 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.

NEWS
src/groups.c
src/id.c

diff --git a/NEWS b/NEWS
index 473b7c21d87498df1989d8c5e871438439691c69..7d46a5bcef2d5ff6f190bde2b485cd843d34033e 100644 (file)
--- 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.
index 3daf410d9faeb29819931d6df1089578aa83c679..57acd376bcf95fbb5f32c430ba9014862a0de0d5 100644 (file)
@@ -135,7 +135,7 @@ main (int argc, char **argv)
             ok = false;
           putchar ('\n');
 
-          if (fflush (stdout) < 0)
+          if (ferror (stdout))
             write_error ();
         }
     }
index 02c3bf9b505fe730350d409704e4cb9e1565f673..27b3e8b708da340e3865293f0d77e428fc1aa75c 100644 (file)
--- 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 ();
 }