diff --git a/libc/string.cc b/libc/string.cc index 5e49200d227d063124a1b55ec8bc1b96c6c49f6f..e55fb5470efae27c699240bdcf4a7cd6ebf21e8e 100644 --- a/libc/string.cc +++ b/libc/string.cc @@ -57,3 +57,16 @@ char* strdup(const char *s) auto p = static_cast<char*>(malloc(strlen(s)+1)); return strcpy(p, s); } + +int strncmp(const char *s1, const char *s2, size_t n) +{ + while (n && *s1 && *s2 && tolower(*s1) == tolower(*s2)) { + ++s1; + ++s2; + --n; + } + if (n == 0) { + return 0; + } + return int(tolower(*s2)) - int(tolower(*s1)); +}