diff options
author | 2006-09-18 21:11:50 +0000 | |
---|---|---|
committer | 2006-09-18 21:11:50 +0000 | |
commit | 76a650ec6b7bd4895bee4f425b64c9fff0977ea3 (patch) | |
tree | fb12192c9ffc606a8911bd5121d3c821cc71cbab | |
parent | +MLINK pcap.3 pcap_get_selectable_fd.3 (diff) | |
download | wireguard-openbsd-76a650ec6b7bd4895bee4f425b64c9fff0977ea3.tar.xz wireguard-openbsd-76a650ec6b7bd4895bee4f425b64c9fff0977ea3.zip |
Add a hand rolled 64bit hex printf that can be used outside of
LIBSA_LONGLONG_PRINTF which requires 64bit math support.
With help from mickey@
Tested on i386, amd64 and on alpha by mickey@
OK mickey@, miod@, deraadt@
-rw-r--r-- | sys/lib/libsa/printf.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/sys/lib/libsa/printf.c b/sys/lib/libsa/printf.c index 24bdc640d36..a820fcbde5a 100644 --- a/sys/lib/libsa/printf.c +++ b/sys/lib/libsa/printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printf.c,v 1.23 2004/09/22 22:05:11 miod Exp $ */ +/* $OpenBSD: printf.c,v 1.24 2006/09/18 21:11:50 mpf Exp $ */ /* $NetBSD: printf.c,v 1.10 1996/11/30 04:19:21 gwr Exp $ */ /*- @@ -67,6 +67,8 @@ void kprintn64(void (*)(int), u_int64_t, int); #endif void kdoprnt(void (*)(int), const char *, va_list); +const char hexdig[] = "0123456789abcdef"; + void printf(const char *fmt, ...) { @@ -194,7 +196,23 @@ reswitch: switch (ch = *fmt++) { ull = va_arg(ap, u_int64_t); kprintn64(put, ull, 16); break; - } + } +#else + if (lflag > 1) { + /* hold an int64_t in base 16 */ + char *p, buf[(sizeof(u_int64_t) * NBBY / 4) + 1]; + u_int64_t ull; + + ull = va_arg(ap, u_int64_t); + p = buf; + do { + *p++ = hexdig[ull & 15]; + } while (ull >>= 4); + do { + put(*--p); + } while (p > buf); + break; + } #endif ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int); @@ -222,7 +240,7 @@ kprintn(void (*put)(int), unsigned long ul, int base) p = buf; do { - *p++ = "0123456789abcdef"[ul % base]; + *p++ = hexdig[ul % base]; } while (ul /= base); do { put(*--p); @@ -238,7 +256,7 @@ kprintn64(void (*put)(int), u_int64_t ull, int base) p = buf; do { - *p++ = "0123456789abcdef"[ull % base]; + *p++ = hexdig[ull % base]; } while (ull /= base); do { put(*--p); |