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

src/hostid.c

index ff30079a70ea79ea5f36722c7b55aa9b53639575..92c252847866b2f10a0c1e1a5c91d1adc2037481 100644 (file)
@@ -52,8 +52,6 @@ Print the numeric identifier (in hexadecimal) for the current host.\n\
 int
 main (int argc, char **argv)
 {
-  unsigned int id;
-
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
@@ -72,12 +70,10 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  id = gethostid ();
-
   /* POSIX says gethostid returns a "32-bit identifier" but is silent
      whether it's sign-extended.  Turn off any sign-extension.  This
      is a no-op unless unsigned int is wider than 32 bits.  */
-  id &= 0xffffffff;
+  unsigned int id = gethostid () & 0xffffffff;
 
   printf ("%08x\n", id);