From e5077ed02c7e617583fe381db77de6e0faac1af6 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 10 Oct 2021 15:43:36 +0000 Subject: init/stdlib: implement strcmp --- src/init/stdlib.c | 11 +++++++++++ src/init/stdlib.h | 1 + 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/init/stdlib.c b/src/init/stdlib.c index 4bc90d2..3714324 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -13,6 +13,17 @@ int memcmp(const void *s1, const void *s2, size_t n) { return 0; } +int strcmp(const char *s1, const char *s2) { + while (*s1) { + if (*s1 != *s2) { + if (*s1 < *s2) return -1; + else return 1; + } + s1++; s2++; + } + return 0; +} + size_t strlen(const char *s) { size_t c = 0; while (*s++) c++; diff --git a/src/init/stdlib.h b/src/init/stdlib.h index 3e56beb..a3a8b64 100644 --- a/src/init/stdlib.h +++ b/src/init/stdlib.h @@ -6,6 +6,7 @@ int memcmp(const void *s1, const void *s2, size_t n); +int strcmp(const char *s1, const char *s2); size_t strlen(const char *s); int printf(const char *fmt, ...); -- cgit v1.2.3