[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patch] 5.2.1 (hostid): don't display sign-extended part
From: |
Paul Eggert |
Subject: |
Re: [patch] 5.2.1 (hostid): don't display sign-extended part |
Date: |
Thu, 16 Jun 2005 16:51:33 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) |
Thanks for reporting the bug. That fix isn't quite right, since it attempts
to print a "long" with "lx"; this has undefined behavior.
Also, you put an "8" into the format without mentioning the issue of
print width. I like the idea of fixed-width (that's what Solaris
does) but it should be zero-padded, not space padded.
I installed the following fix instead.
2005-06-16 Paul Eggert <address@hidden>
* 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.
Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.296
diff -p -u -r1.296 NEWS
--- NEWS 15 Jun 2005 00:06:34 -0000 1.296
+++ NEWS 16 Jun 2005 23:44:37 -0000
@@ -131,6 +131,9 @@ GNU coreutils NEWS
** 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: src/hostid.c
===================================================================
RCS file: /fetish/cu/src/hostid.c,v
retrieving revision 1.31
diff -p -u -r1.31 hostid.c
--- src/hostid.c 14 May 2005 07:58:37 -0000 1.31
+++ src/hostid.c 16 Jun 2005 23:44:37 -0000
@@ -62,7 +62,7 @@ Print the numeric identifier (in hexadec
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);
}