fix: kprintf support first argument
This commit is contained in:
parent
2cbe9c9492
commit
27ec2f24c2
@ -9,6 +9,8 @@
|
|||||||
static int print_flag(char flag, va_list ap)
|
static int print_flag(char flag, va_list ap)
|
||||||
{
|
{
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
|
case '%':
|
||||||
|
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':
|
||||||
@ -25,21 +27,17 @@ int kvprintf(int level, const char *restrict format, va_list ap)
|
|||||||
{
|
{
|
||||||
const char *start = format;
|
const char *start = format;
|
||||||
const char *flag;
|
const char *flag;
|
||||||
long padding;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
while (*start != '\0') {
|
while (*start != '\0') {
|
||||||
flag = strchr(start, '%');
|
if (*start == '%' && *(start + 1) != '\0') {
|
||||||
if (flag != NULL) {
|
ret += print_flag(*(start + 1), ap);
|
||||||
padding = atoll(start + 1);
|
start++;
|
||||||
for (; isdigit(*flag); flag++);
|
|
||||||
ret += print_flag(*flag, ap);
|
|
||||||
start = flag + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
terminal_writestring(start);
|
|
||||||
start += strlen(start);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
ret += terminal_putchar(*start);
|
||||||
|
start++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user