1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-07-26 18:48:55 +02:00

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.
This commit is contained in:
Paul Eggert
2026-02-27 16:17:27 -08:00
parent 02983e4935
commit d41e1375cb
3 changed files with 4 additions and 5 deletions
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -135,7 +135,7 @@ main (int argc, char **argv)
ok = false;
putchar ('\n');
if (fflush (stdout) < 0)
if (ferror (stdout))
write_error ();
}
}
+2 -3
View File
@@ -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 ();
}