From 44d308149282debf314cb48789b9084767c1c288 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 6 Oct 2021 06:34:23 +0000 Subject: init printf: implement %s --- src/init/stdlib.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/init/stdlib.c') diff --git a/src/init/stdlib.c b/src/init/stdlib.c index 56d6da6..876c74c 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -29,8 +29,22 @@ int printf(const char *fmt, ...) { switch (c) { case '\0': // TODO don't assume that stdout is @ fd 0 - _syscall_write(0, seg, fmt - seg, 0); - return total + (fmt - seg); + _syscall_write(0, seg, fmt - seg - 1, 0); + return total + (fmt - seg - 1); + + case '%': + _syscall_write(0, seg, fmt - seg - 1, 0); + total += fmt - seg - 1; + c = *fmt++; + switch (c) { + case 's': + const char *s = va_arg(argp, char*); + _syscall_write(0, s, strlen(s), 0); + total += strlen(s); + break; + } + seg = fmt; + break; } } } -- cgit v1.2.3