summaryrefslogtreecommitdiff
path: root/src/init/stdlib.c
diff options
context:
space:
mode:
authordzwdz2021-10-06 06:34:23 +0000
committerdzwdz2021-10-06 06:34:23 +0000
commit44d308149282debf314cb48789b9084767c1c288 (patch)
tree1bc1e378bcfa7fbda90957544aa2b5d9444bc106 /src/init/stdlib.c
parent381f9b26bd31072530d795c38c19ce3dd69954a6 (diff)
init printf: implement %s
Diffstat (limited to 'src/init/stdlib.c')
-rw-r--r--src/init/stdlib.c18
1 files changed, 16 insertions, 2 deletions
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;
}
}
}