diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/stdio/vsnprintf.c | 18 | ||||
-rw-r--r-- | libc/test/run-time.c | 1 |
2 files changed, 10 insertions, 9 deletions
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c index d1cd4e3..b2f0b94 100644 --- a/libc/stdio/vsnprintf.c +++ b/libc/stdio/vsnprintf.c @@ -29,22 +29,22 @@ print_itoa(char **buffer, unsigned long value, unsigned short base, bool upper) { const char zeichen[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; char c; + int i = 0; + char tmp[16]; if(base <= 2 || base > 16) return 0; - if (value < base) { - c = zeichen[value]; - if (upper) - c = toupper(c); - **buffer = c; - *buffer += 1; - } else { - print_itoa(buffer, value / base, base, upper); + do { c = zeichen[value % base]; if (upper) c = toupper(c); - **buffer = c; + tmp[i++] = c; + value /= base; + } while(value); + + while (i--) { + **buffer = tmp[i]; *buffer += 1; } diff --git a/libc/test/run-time.c b/libc/test/run-time.c index b0a221d..0f377b5 100644 --- a/libc/test/run-time.c +++ b/libc/test/run-time.c @@ -1,6 +1,7 @@ #include "/usr/include/assert.h" #include <stdio.h> #include <time.h> +#include <stdint.h> #include "../time.c" |