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.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init/stdlib.h') diff --git a/src/init/stdlib.h b/src/init/stdlib.h index 1cabc7a..357a396 100644 --- a/src/init/stdlib.h +++ b/src/init/stdlib.h @@ -5,3 +5,5 @@ // stb-style header file int memcmp(const void *s1, const void *s2, size_t n); + +int printf(const char *fmt, ...); -- cgit v1.2.3 From 381f9b26bd31072530d795c38c19ce3dd69954a6 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 6 Oct 2021 06:32:29 +0000 Subject: init: implement strlen --- src/init/stdlib.c | 6 ++++++ src/init/stdlib.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src/init/stdlib.h') diff --git a/src/init/stdlib.c b/src/init/stdlib.c index ac80c28..56d6da6 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -13,6 +13,12 @@ int memcmp(const void *s1, const void *s2, size_t n) { return 0; } +size_t strlen(const char *s) { + size_t c = 0; + while (*s++) c++; + return c; +} + int printf(const char *fmt, ...) { const char *seg = fmt; // beginning of the current segment int total = 0; diff --git a/src/init/stdlib.h b/src/init/stdlib.h index 357a396..3e56beb 100644 --- a/src/init/stdlib.h +++ b/src/init/stdlib.h @@ -6,4 +6,6 @@ int memcmp(const void *s1, const void *s2, size_t n); +size_t strlen(const char *s); + int printf(const char *fmt, ...); -- cgit v1.2.3