diff --git a/include/string.h b/include/string.h index 8e87086..c4a93bd 100644 --- a/include/string.h +++ b/include/string.h @@ -12,6 +12,7 @@ char *strchr(const char *s, int c); int strcmp(const char *s1, const char *s2); char *strcpy(char *to, const char *from); size_t strlen(const char *str); +int strncmp(const char *s1, const char *s2, size_t len); char *strncpy(char *to, const char *from, size_t len); #endif /* __STRING_H__ */ diff --git a/sys/kern/libc.c b/sys/kern/libc.c index 16b4336..ec3730b 100644 --- a/sys/kern/libc.c +++ b/sys/kern/libc.c @@ -53,6 +53,27 @@ strcmp(const char *s1, const char *s2) return (*(const uint8_t *)s1 - *(const uint8_t *)(s2 - 1)); } +int +strncmp(const char *s1, const char *s2, size_t len) +{ + if (len == 0) + return 0; + + while (*s1 == *s2) { + if (*s1 == 0) + return 0; + + s1++; + s2++; + + len--; + if (len == 0) + return 0; + } + + return (*(const uint8_t *)s1 - *(const uint8_t *)s2); +} + size_t strlen(const char *str) {