* src/hostid.c (main): Don't print fewer than 8 digits, or spurious leading "f".
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jun 2005 23:46:27 +0000 (23:46 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 16 Jun 2005 23:46:27 +0000 (23:46 +0000)
ChangeLog
NEWS
src/hostid.c

index 9c6e8e3..1f46497 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,13 @@
-2005-06-16  Jim Meyering  <jim@meyering.net>
+2005-06-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        * Version 5.3.1.
 
+       * src/hostid.c (main): Don't print fewer than 8 digits, or spurious
+       leading "f"s.  "f" problem reported by Tim Waugh.
+       * NEWS: Document this.
+
+2005-06-16  Jim Meyering  <jim@meyering.net>
+
        Don't embed `this'-style quotes in format strings.
        * src/tr.c: Rather than this: error (..., "...`%s'...", arg);
        do this:                      error (..., "...%s...", quote (arg));
diff --git a/NEWS b/NEWS
index 759ac6a..073fe09 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -131,6 +131,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Improved portability
 
+  hostid now prints exactly 8 hexadecimal digits, possibly with leading zeros,
+  and without any spurious leading "fff..." on 64-bit hosts.
+
   nice now works on Darwin 7.7.0 in spite of its invalid definition of NZERO.
 
   `rm -r' can remove all entries in a directory even when it is on a
index 477d16e..090b8a0 100644 (file)
@@ -62,7 +62,7 @@ Print the numeric identifier (in hexadecimal) for the current host.\n\
 int
 main (int argc, char **argv)
 {
-  long int id;
+  unsigned int id;
 
   initialize_main (&argc, &argv);
   program_name = argv[0];
@@ -84,7 +84,13 @@ main (int argc, char **argv)
     }
 
   id = gethostid ();
-  printf ("%lx\n", id);
+
+  /* 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;
+
+  printf ("%08x\n", id);
 
   exit (EXIT_SUCCESS);
 }