diff --git a/libc/malloc/dprintf.c b/libc/malloc/dprintf.c index c83fd1050..1a2482fe4 100644 --- a/libc/malloc/dprintf.c +++ b/libc/malloc/dprintf.c @@ -4,16 +4,21 @@ #include #include -static char *uitostr(unsigned int val, int radix, int width) +static char *fmtultostr(unsigned long val, int radix, int width) { - static char buf[6]; + static char buf[34]; char *p = buf + sizeof(buf) - 1; unsigned int c; *p = '\0'; do { +#ifdef _M_I86 + c = radix; + val = __divmod(val, &c); +#else c = val % radix; val = val / radix; +#endif if (c > 9) *--p = 'a' - 10 + c; else @@ -28,19 +33,22 @@ static char *uitostr(unsigned int val, int radix, int width) /* * Very tiny printf to console. * Supports: - * %{0-9} width + * %{0-9} field width + * %l{u,d,x,p} * %u unsigned decimal * %d decimal (positive numbers only) - * %p zero-fill hexadecimal width 4 + * %p pointer (zero-filled hexadecimal) * %x hexadecimal * %s string */ int __dprintf(const char *fmt, ...) { unsigned int n; + unsigned long val; int radix, width; char *p; va_list va; + int lval; char b[80]; static int fd = -1; @@ -55,6 +63,7 @@ int __dprintf(const char *fmt, ...) if (*fmt == '%') { ++fmt; width = 0; + lval = 0; while (*fmt >= '0' && *fmt <= '9') { width = width * 10 + *fmt - '0'; fmt++; @@ -62,12 +71,17 @@ int __dprintf(const char *fmt, ...) again: switch (*fmt) { case 'l': - fmt++; goto again; + lval = 1; + fmt++; + goto again; case 's': p = va_arg(va, char *); goto outstr; case 'p': - width = 4; + if (sizeof(char *) == sizeof(unsigned long)) + lval = 1; + width = lval? 8: 4; + /* fall through */ case 'x': radix = 16; goto convert; @@ -75,7 +89,8 @@ int __dprintf(const char *fmt, ...) case 'u': radix = 10; convert: - p = uitostr(va_arg(va, unsigned int), radix, width); + val = lval? va_arg(va, unsigned long): va_arg(va, unsigned int); + p = fmtultostr(val, radix, width); outstr: while (*p && n < sizeof(b)) b[n++] = *p++; diff --git a/libc/malloc/fmemalloc.c b/libc/malloc/fmemalloc.c index 27bb223e4..78506be1a 100644 --- a/libc/malloc/fmemalloc.c +++ b/libc/malloc/fmemalloc.c @@ -36,7 +36,7 @@ void __far *fmemalloc(unsigned long size) #if DEBUG total += size; if (size > maxsize) maxsize = size; - debug("total %lu, maxsize %lu\n", (unsigned)total, (unsigned)maxsize); + debug("total %lu, maxsize %lu\n", total, maxsize); #endif return MK_FP(seg, 0); }