diff options
author | davidxu <davidxu@FreeBSD.org> | 2003-08-19 08:29:33 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2003-08-19 08:29:33 +0000 |
commit | 00e9963efb647fd5a8d8eb9037df311d937c6bae (patch) | |
tree | a15776fbdc7aebe733e4448f6ea466f001b477b2 | |
parent | 7166b89595c332e02c04e1d367bbd0b33e42b233 (diff) | |
download | FreeBSD-src-00e9963efb647fd5a8d8eb9037df311d937c6bae.zip FreeBSD-src-00e9963efb647fd5a8d8eb9037df311d937c6bae.tar.gz |
Support printing 64 bits pointer and long integer.
Reviewed by: deischen
-rw-r--r-- | lib/libkse/thread/thr_printf.c | 37 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_printf.c | 37 |
2 files changed, 54 insertions, 20 deletions
diff --git a/lib/libkse/thread/thr_printf.c b/lib/libkse/thread/thr_printf.c index f0791df..b4a156d 100644 --- a/lib/libkse/thread/thr_printf.c +++ b/lib/libkse/thread/thr_printf.c @@ -54,15 +54,20 @@ _thread_printf(int fd, const char *fmt, ...) { static const char digits[16] = "0123456789abcdef"; va_list ap; - char buf[10]; + char buf[20]; char *s; - unsigned r, u; - int c, d; + unsigned long r, u; + int c; + long d; + int islong; va_start(ap, fmt); while ((c = *fmt++)) { + islong = 0; if (c == '%') { - c = *fmt++; +next: c = *fmt++; + if (c == '\0') + goto out; switch (c) { case 'c': pchar(fd, va_arg(ap, int)); @@ -70,20 +75,31 @@ _thread_printf(int fd, const char *fmt, ...) case 's': pstr(fd, va_arg(ap, char *)); continue; + case 'l': + islong = 1; + goto next; + case 'p': + islong = 1; case 'd': case 'u': - case 'p': case 'x': r = ((c == 'u') || (c == 'd')) ? 10 : 16; if (c == 'd') { - d = va_arg(ap, unsigned); + if (islong) + d = va_arg(ap, unsigned long); + else + d = va_arg(ap, unsigned); if (d < 0) { pchar(fd, '-'); - u = (unsigned)(d * -1); + u = (unsigned long)(d * -1); } else - u = (unsigned)d; - } else - u = va_arg(ap, unsigned); + u = (unsigned long)d; + } else { + if (islong) + u = va_arg(ap, unsigned long); + else + u = va_arg(ap, unsigned); + } s = buf; do { *s++ = digits[u % r]; @@ -95,6 +111,7 @@ _thread_printf(int fd, const char *fmt, ...) } pchar(fd, c); } +out: va_end(ap); } diff --git a/lib/libpthread/thread/thr_printf.c b/lib/libpthread/thread/thr_printf.c index f0791df..b4a156d 100644 --- a/lib/libpthread/thread/thr_printf.c +++ b/lib/libpthread/thread/thr_printf.c @@ -54,15 +54,20 @@ _thread_printf(int fd, const char *fmt, ...) { static const char digits[16] = "0123456789abcdef"; va_list ap; - char buf[10]; + char buf[20]; char *s; - unsigned r, u; - int c, d; + unsigned long r, u; + int c; + long d; + int islong; va_start(ap, fmt); while ((c = *fmt++)) { + islong = 0; if (c == '%') { - c = *fmt++; +next: c = *fmt++; + if (c == '\0') + goto out; switch (c) { case 'c': pchar(fd, va_arg(ap, int)); @@ -70,20 +75,31 @@ _thread_printf(int fd, const char *fmt, ...) case 's': pstr(fd, va_arg(ap, char *)); continue; + case 'l': + islong = 1; + goto next; + case 'p': + islong = 1; case 'd': case 'u': - case 'p': case 'x': r = ((c == 'u') || (c == 'd')) ? 10 : 16; if (c == 'd') { - d = va_arg(ap, unsigned); + if (islong) + d = va_arg(ap, unsigned long); + else + d = va_arg(ap, unsigned); if (d < 0) { pchar(fd, '-'); - u = (unsigned)(d * -1); + u = (unsigned long)(d * -1); } else - u = (unsigned)d; - } else - u = va_arg(ap, unsigned); + u = (unsigned long)d; + } else { + if (islong) + u = va_arg(ap, unsigned long); + else + u = va_arg(ap, unsigned); + } s = buf; do { *s++ = digits[u % r]; @@ -95,6 +111,7 @@ _thread_printf(int fd, const char *fmt, ...) } pchar(fd, c); } +out: va_end(ap); } |