]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: whoami: reduce variable scope
authorCollin Funk <collin.funk1@gmail.com>
Sun, 7 Dec 2025 23:03:00 +0000 (15:03 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Sun, 7 Dec 2025 23:03:00 +0000 (15:03 -0800)
* src/whoami.c (main): Declare variables where they are used instead of
at the start of the function.

src/whoami.c

index 9313eaf3e492e12978794723a97f4a0fc016583c..47c7c55b8a6374d6c7a074dfa6b7ee9a616c7a66 100644 (file)
@@ -55,8 +55,6 @@ Same as id -un.\n\
 int
 main (int argc, char **argv)
 {
-  struct passwd *pw;
-  uid_t uid;
   uid_t NO_UID = -1;
 
   initialize_main (&argc, &argv);
@@ -78,8 +76,8 @@ main (int argc, char **argv)
     }
 
   errno = 0;
-  uid = geteuid ();
-  pw = uid == NO_UID && errno ? nullptr : getpwuid (uid);
+  uid_t uid = geteuid ();
+  struct passwd *pw = uid == NO_UID && errno ? nullptr : getpwuid (uid);
   if (!pw)
     error (EXIT_FAILURE, errno, _("cannot find name for user ID %ju"),
            (uintmax_t) uid);