summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authordzwdz2021-10-06 06:34:23 +0000
committerdzwdz2021-10-06 06:34:23 +0000
commit44d308149282debf314cb48789b9084767c1c288 (patch)
tree1bc1e378bcfa7fbda90957544aa2b5d9444bc106 /src/init
parent381f9b26bd31072530d795c38c19ce3dd69954a6 (diff)
init printf: implement %s
Diffstat (limited to 'src/init')
-rw-r--r--src/init/main.c2
-rw-r--r--src/init/stdlib.c18
2 files changed, 17 insertions, 3 deletions
diff --git a/src/init/main.c b/src/init/main.c
index a819152..7c827eb 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -29,7 +29,7 @@ int main(void) {
fs_test();
test_await();
- printf("printf test\n");
+ printf("%s\n", "printf test");
char c;
while (_syscall_read(tty_fd, &c, 1, 0))
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;
}
}
}