Import strncmp()

This commit is contained in:
Pierre Pronchery 2018-06-08 00:23:14 -04:00
parent ffdc7343f4
commit bac9bd3bf2
2 changed files with 18 additions and 0 deletions

View File

@ -19,5 +19,6 @@ void * memset(void * dest, int c, size_t n);
int strcmp(char const * s1, char const * s2);
char * strcpy(char * dest, char const * src);
size_t strlen(char const * s);
int strncmp(char const * s1, char const * s2, size_t n);
#endif /* !UKERNEL_STRING_H */

View File

@ -107,3 +107,20 @@ size_t strlen(char const * s)
len++;
return len;
}
/* strncmp */
int strncmp(char const * s1, char const * s2, size_t n)
{
unsigned char const * u1;
unsigned char const * u2;
u1 = (unsigned char const *)s1;
u2 = (unsigned char const *)s2;
while(--n && *u1 && *u2 && *u1 == *u2)
{
u1++;
u2++;
}
return *u1 - *u2;
}