summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-06-16 23:46:27 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-06-16 23:46:27 +0000
commit4df24112903cb00012e164657f14f2d08ec9efca (patch)
treeaa0dd4d77591341403a64741b5a806e54951636e /src
parent0812004419be11386ad11e51603cc3ef085662e9 (diff)
downloadcoreutils-4df24112903cb00012e164657f14f2d08ec9efca.tar.xz
* src/hostid.c (main): Don't print fewer than 8 digits, or spurious leading "f".
Diffstat (limited to 'src')
-rw-r--r--src/hostid.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/hostid.c b/src/hostid.c
index 477d16e4a..090b8a04c 100644
--- a/src/hostid.c
+++ b/src/hostid.c
@@ -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);
}