Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/lib/libc/net Pull up revision 1.19 (via patch, requeste...



details:   https://anonhg.NetBSD.org/src/rev/3caf4d3dafe9
branches:  netbsd-1-4
changeset: 471150:3caf4d3dafe9
user:      he <he%NetBSD.org@localhost>
date:      Thu Oct 19 18:34:33 2000 +0000

description:
Pull up revision 1.19 (via patch, requested by is):
  Construct format string at compile time.

diffstat:

 lib/libc/net/ethers.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (31 lines):

diff -r 1d391743d485 -r 3caf4d3dafe9 lib/libc/net/ethers.c
--- a/lib/libc/net/ethers.c     Thu Oct 19 18:23:01 2000 +0000
+++ b/lib/libc/net/ethers.c     Thu Oct 19 18:34:33 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ethers.c,v 1.14 1998/11/13 15:46:53 christos Exp $     */
+/*     $NetBSD: ethers.c,v 1.14.2.1 2000/10/19 18:34:33 he Exp $       */
 
 /* 
  * ethers(3N) a la Sun.
@@ -184,13 +184,15 @@
        char *hostname;
 {
        u_int i[6];
-       static char buf[sizeof " %x:%x:%x:%x:%x:%x %s\\n" + 21];
-               /* XXX: 21 == strlen (ASCII representation of 2^64) */
 
-       if (! buf[0])
-               snprintf(buf, sizeof buf, " %%x:%%x:%%x:%%x:%%x:%%x %%%ds\\n",
-                   MAXHOSTNAMELEN);
-       if (sscanf(l, buf,
+#define S2(arg) #arg
+#define S1(arg) S2(arg)
+       const static char fmt[] = " %x:%x:%x:%x:%sx:%x"
+           " %" S1(MAXHOSTNAMELEN) "s\n";
+#undef S2
+#undef S1
+
+       if (sscanf(l, fmt,
            &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], hostname) == 7) {
                e->ether_addr_octet[0] = (u_char)i[0];
                e->ether_addr_octet[1] = (u_char)i[1];



Home | Main Index | Thread Index | Old Index