From a3469d648a4d0f276d979ceb14b8716b46f4f72e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 6 Oct 2021 06:28:04 +0000 Subject: init: printf base --- src/init/stdlib.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/init/stdlib.c') diff --git a/src/init/stdlib.c b/src/init/stdlib.c index 6ed5a0a..ac80c28 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -1,4 +1,6 @@ #include +#include +#include int memcmp(const void *s1, const void *s2, size_t n) { const unsigned char *c1 = s1, *c2 = s2; @@ -10,3 +12,19 @@ int memcmp(const void *s1, const void *s2, size_t n) { } return 0; } + +int printf(const char *fmt, ...) { + const char *seg = fmt; // beginning of the current segment + int total = 0; + va_list argp; + va_start(argp, fmt); + for (;;) { + char c = *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); + } + } +} -- cgit v1.2.3