Skip to content
Snippets Groups Projects
Commit 91d79a1a authored by Avi Kivity's avatar Avi Kivity
Browse files

string: implement strncmp()

parent 55376a1f
No related branches found
No related tags found
No related merge requests found
...@@ -57,3 +57,16 @@ char* strdup(const char *s) ...@@ -57,3 +57,16 @@ char* strdup(const char *s)
auto p = static_cast<char*>(malloc(strlen(s)+1)); auto p = static_cast<char*>(malloc(strlen(s)+1));
return strcpy(p, s); 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));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment