libc: fix bad strncmp

This commit is contained in:
K. Lange 2018-10-12 13:10:46 +09:00
parent 07fae13402
commit e492f967c0
1 changed files with 5 additions and 6 deletions

View File

@ -1,13 +1,12 @@
#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n) {
size_t i = 0;
while (i < n && *s1 && *s2) {
if (*s1 < *s2) return -1;
if (*s1 > *s2) return 1;
if (n == 0) return 0;
while (n-- && *s1 == *s2) {
if (!n || !*s1) break;
s1++;
s2++;
i++;
}
return 0;
return (*(unsigned char *)s1) - (*(unsigned char *)s2);
}