From 907eb7cf7d4dd493033e07f92a2f8c106eb7d7a6 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Sat, 7 Sep 2024 12:18:59 +0200 Subject: [PATCH] fix: kprintf now works with multiple arguments --- src/kprint/kvprintf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/kprint/kvprintf.c b/src/kprint/kvprintf.c index 6b8cb11..2f18982 100644 --- a/src/kprint/kvprintf.c +++ b/src/kprint/kvprintf.c @@ -1,24 +1,24 @@ +#include "ctype.h" #include "kprintf.h" +#include "stdlib.h" #include "string.h" #include "terminal.h" -#include "ctype.h" -#include "stdlib.h" #include -static int print_flag(char flag, va_list ap) +static int print_flag(char flag, va_list *ap) { switch (flag) { - case '%': - return terminal_putchar('%'); - case 'i': - return terminal_writelong(va_arg(ap, int)); - case 'd': - return terminal_writelong(va_arg(ap, int)); - case 'c': - return terminal_putchar(va_arg(ap, int)); - case 's': - return terminal_writestring(va_arg(ap, char *)); + case '%': + return terminal_putchar('%'); + case 'i': + return terminal_writelong(va_arg(*ap, int)); + case 'd': + return terminal_writelong(va_arg(*ap, int)); + case 'c': + return terminal_putchar(va_arg(*ap, int)); + case 's': + return terminal_writestring(va_arg(*ap, char *)); } return 0; } @@ -30,12 +30,12 @@ int kvprintf(int level, const char *restrict format, va_list ap) while (*start != '\0') { if (*start == '%' && *(start + 1) != '\0') { - ret += print_flag(*(start + 1), ap); + ret += print_flag(*(start + 1), &ap); start++; - } - else + } else { ret += terminal_putchar(*start); + } start++; } return ret; -} \ No newline at end of file +}