Remove apparent recursion from strcmp and strncmp

This commit is contained in:
Ryan Dwyer 2022-12-01 19:09:56 +10:00
parent e59fc870ad
commit d6123cbe72
1 changed files with 32 additions and 26 deletions

View File

@ -80,42 +80,48 @@ char *strcat(char *dst, const char *src)
s32 strcmp(const char *s1, const char *s2)
{
if (*s1 != *s2) {
if (*s1 < *s2) {
return -1;
} else {
return 1;
while (true) {
if (*s1 != *s2) {
if (*s1 < *s2) {
return -1;
} else {
return 1;
}
}
}
if (*s1 == '\0') {
return 0;
}
if (*s1 == '\0') {
return 0;
}
return strcmp(s1 + 1, s2 + 1);
s1++;
s2++;
}
}
s32 strncmp(const char *s1, const char *s2, s32 len)
{
if (len == 0) {
return 0;
}
len--;
if (*s1 != *s2) {
if (*s1 < *s2) {
return -1;
} else {
return 1;
while (true) {
if (len == 0) {
return 0;
}
}
if (*s1 == '\0') {
return 0;
}
if (*s1 != *s2) {
if (*s1 < *s2) {
return -1;
} else {
return 1;
}
}
return strncmp(s1 + 1, s2 + 1, len);
if (*s1 == '\0') {
return 0;
}
len--;
s1++;
s2++;
}
}
char toupper(char c)