libc: fix bad strncmp
This commit is contained in:
parent
07fae13402
commit
e492f967c0
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user