fix: kprintf now works with multiple arguments

This commit is contained in:
0x35c 2024-09-07 12:18:59 +02:00
parent 8968c3769d
commit 907eb7cf7d

View File

@ -1,24 +1,24 @@
#include "ctype.h"
#include "kprintf.h" #include "kprintf.h"
#include "stdlib.h"
#include "string.h" #include "string.h"
#include "terminal.h" #include "terminal.h"
#include "ctype.h"
#include "stdlib.h"
#include <stdarg.h> #include <stdarg.h>
static int print_flag(char flag, va_list ap) static int print_flag(char flag, va_list *ap)
{ {
switch (flag) { switch (flag) {
case '%': case '%':
return terminal_putchar('%'); return terminal_putchar('%');
case 'i': case 'i':
return terminal_writelong(va_arg(ap, int)); return terminal_writelong(va_arg(*ap, int));
case 'd': case 'd':
return terminal_writelong(va_arg(ap, int)); return terminal_writelong(va_arg(*ap, int));
case 'c': case 'c':
return terminal_putchar(va_arg(ap, int)); return terminal_putchar(va_arg(*ap, int));
case 's': case 's':
return terminal_writestring(va_arg(ap, char *)); return terminal_writestring(va_arg(*ap, char *));
} }
return 0; return 0;
} }
@ -30,11 +30,11 @@ int kvprintf(int level, const char *restrict format, va_list ap)
while (*start != '\0') { while (*start != '\0') {
if (*start == '%' && *(start + 1) != '\0') { if (*start == '%' && *(start + 1) != '\0') {
ret += print_flag(*(start + 1), ap); ret += print_flag(*(start + 1), &ap);
start++; start++;
} } else {
else
ret += terminal_putchar(*start); ret += terminal_putchar(*start);
}
start++; start++;
} }
return ret; return ret;