summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2021-10-10 15:43:36 +0000
committerdzwdz2021-10-10 15:43:36 +0000
commite5077ed02c7e617583fe381db77de6e0faac1af6 (patch)
treeb8ce8a2433e8b613c3de6905897b679fadea52db /src
parente95ab7393a267f15fb7be915efb2538382bbf838 (diff)
init/stdlib: implement strcmp
Diffstat (limited to 'src')
-rw-r--r--src/init/stdlib.c11
-rw-r--r--src/init/stdlib.h1
2 files changed, 12 insertions, 0 deletions
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, ...);