From b1ba0f3843ddf077401826e0c59e35aa0ffaeaa5 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Tue, 9 Dec 2025 21:48:50 -0800 Subject: [PATCH] maint: groups: reduce variable scope * src/groups.c (main): Declare variables where they are used instead of at the start of the function. Convert a comment to GNU style. --- src/groups.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/groups.c b/src/groups.c index f01ed7dccb..4a491f5877 100644 --- a/src/groups.c +++ b/src/groups.c @@ -66,11 +66,6 @@ the current process (which may differ if the groups database has changed).\n"), int main (int argc, char **argv) { - int optc; - bool ok = true; - gid_t rgid, egid; - uid_t ruid; - initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); @@ -80,8 +75,8 @@ main (int argc, char **argv) atexit (close_stdout); /* Processing the arguments this way makes groups.c behave differently to - * groups.sh if one of the arguments is "--". - */ + groups.sh if one of the arguments is "--". */ + int optc; while ((optc = getopt_long (argc, argv, "", longopts, nullptr)) != -1) { switch (optc) @@ -93,6 +88,7 @@ main (int argc, char **argv) } } + bool ok = true; if (optind == argc) { /* No arguments. Divulge the details of the current process. */ @@ -100,17 +96,17 @@ main (int argc, char **argv) gid_t NO_GID = -1; errno = 0; - ruid = getuid (); + uid_t ruid = getuid (); if (ruid == NO_UID && errno) error (EXIT_FAILURE, errno, _("cannot get real UID")); errno = 0; - egid = getegid (); + gid_t egid = getegid (); if (egid == NO_GID && errno) error (EXIT_FAILURE, errno, _("cannot get effective GID")); errno = 0; - rgid = getgid (); + gid_t rgid = getgid (); if (rgid == NO_GID && errno) error (EXIT_FAILURE, errno, _("cannot get real GID")); @@ -130,8 +126,9 @@ main (int argc, char **argv) ok = false; continue; } - ruid = pwd->pw_uid; - rgid = egid = pwd->pw_gid; + uid_t ruid = pwd->pw_uid; + gid_t rgid = pwd->pw_gid; + gid_t egid = rgid; printf ("%s : ", argv[optind]); if (!print_group_list (argv[optind], ruid, rgid, egid, true, ' ')) -- 2.47.3