diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-04-01 21:46:28 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-08-12 10:13:59 +0300 |
commit | 9b777b088facde26c33df6c746b948caff725602 (patch) | |
tree | 3e88f6808e80a233f3e78640d1f2545489665376 /lib/stdio | |
parent | lidt (diff) | |
download | kernel-9b777b088facde26c33df6c746b948caff725602.tar.xz |
printf: add %d, %u and %x
Diffstat (limited to 'lib/stdio')
-rw-r--r-- | lib/stdio/printf.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/stdio/printf.c b/lib/stdio/printf.c index f6b8ef6..269b9b6 100644 --- a/lib/stdio/printf.c +++ b/lib/stdio/printf.c @@ -1,8 +1,11 @@ #include <stdarg.h> #include <stdio.h> +#include <string.h> #include <devices/uart_16550.h> +static char buffer[3 * sizeof(int) + 2]; + int printf(const char *restrict format, ...) { @@ -22,6 +25,15 @@ printf(const char *restrict format, ...) case 's': written += uart_puts(COM1, va_arg(params, const char *), -1); break; + case 'd': + written += uart_puts(COM1, itoa(buffer, va_arg(params, int), 10), -1); + break; + case 'u': + written += uart_puts(COM1, utoa(buffer, va_arg(params, unsigned int), 10), -1); + break; + case 'x': + written += uart_puts(COM1, utoa(buffer, va_arg(params, unsigned int), 16), -1); + break; } l = 0; |