[liba] Add strncmp

This commit is contained in:
Ruben Dashyan
2018-11-02 18:09:28 +01:00
committed by Émilie Feral
parent 93d8f60619
commit efde8c6c9e
2 changed files with 12 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ void * memset(void * b, int c, size_t len);
char * strchr(const char * s, int c);
int strcmp(const char * s1, const char * s2);
int strncmp(const char * s1, const char * s2, size_t n);
size_t strlcpy(char * dst, const char * src, size_t len);
size_t strlen(const char * s);

View File

@@ -7,3 +7,14 @@ int strcmp(const char *s1, const char *s2) {
}
return (*(unsigned char *)s1) - (*(unsigned char *)s2);
}
int strncmp(const char *s1, const char *s2, size_t n) {
while (n-- > 0) {
if (*s1 == NULL || *s2 != *s1) {
return (*(unsigned char *)s1) - (*(unsigned char *)s2);
}
s1++;
s2++;
}
return 0;
}