diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-04-18 07:40:04 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-04-18 07:40:04 +0000 |
commit | 888b63e1743ef4b4277b88169301e0b5c1445e16 (patch) | |
tree | 5b9d1c51879f3e1f909c17e6ec7c2f6050ac92e1 /sys/lib/libsa | |
parent | c2ee71fae9cec63f4a94c921619dc28d1c5b5032 (diff) |
i386 bootblocks that work for 2.3. A tale too long to tell
Diffstat (limited to 'sys/lib/libsa')
-rw-r--r-- | sys/lib/libsa/printf.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/sys/lib/libsa/printf.c b/sys/lib/libsa/printf.c index ad9f454f385..d27e723e727 100644 --- a/sys/lib/libsa/printf.c +++ b/sys/lib/libsa/printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printf.c,v 1.10 1997/07/25 17:28:36 mickey Exp $ */ +/* $OpenBSD: printf.c,v 1.11 1998/04/18 07:39:59 deraadt Exp $ */ /* $NetBSD: printf.c,v 1.10 1996/11/30 04:19:21 gwr Exp $ */ /*- @@ -139,7 +139,7 @@ kdoprnt(put, fmt, ap) register char *p; register int ch; unsigned long ul; - int lflag; + int lflag, zpad; for (;;) { while ((ch = *fmt++) != '%') { @@ -147,8 +147,11 @@ kdoprnt(put, fmt, ap) return; put(ch); } - lflag = 0; + zpad = lflag = 0; reswitch: switch (ch = *fmt++) { + case '0': + zpad = 1; + goto reswitch; case 'l': lflag = 1; goto reswitch; @@ -198,7 +201,7 @@ reswitch: switch (ch = *fmt++) { case 'o': ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int); - kprintn(put, ul, 8); + kprintn(put, ul, (zpad? -8:8)); break; case 'u': ul = lflag ? @@ -206,13 +209,14 @@ reswitch: switch (ch = *fmt++) { kprintn(put, ul, 10); break; case 'p': - putchar('0'); - putchar('x'); + put('0'); + put('x'); + zpad = 1; lflag += sizeof(void *)==sizeof(u_long)? 1 : 0; case 'x': ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int); - kprintn(put, ul, 16); + kprintn(put, ul, (zpad? -16: 16)); break; default: put('%'); @@ -230,13 +234,19 @@ kprintn(put, ul, base) unsigned long ul; int base; { - /* hold a long in base 8 */ - char *p, buf[(sizeof(long) * NBBY / 3) + 1]; +#define NDIGITS(blog) ((sizeof(long) * NBBY + blog - 1) / blog) + char *p, buf[NDIGITS(3) + 1]; /* hold a long in base 8 */ + int zpad = (base==-8)? NDIGITS(3) : ((base==-16)? NDIGITS(4) : 0); + if (base < 0) + base = -base; p = buf; do { *p++ = "0123456789abcdef"[ul % base]; } while (ul /= base); + if (zpad) + while((p - buf) < zpad) + *p++ = '0'; do { put(*--p); } while (p > buf); |