libc: Rename fold() to lowercase() in strcasecmp and strncasecmp

This commit is contained in:
apio 2022-11-06 14:45:58 +01:00
parent da182f1c2f
commit d7692a7f59

View File

@ -2,7 +2,7 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
static char fold(char c) static char lowercase(char c)
{ {
if (isalpha(c)) return (char)tolower(c); if (isalpha(c)) return (char)tolower(c);
return c; return c;
@ -22,22 +22,22 @@ extern "C"
int strcasecmp(const char* a, const char* b) int strcasecmp(const char* a, const char* b)
{ {
while (*a && (fold(*a) == fold(*b))) while (*a && (lowercase(*a) == lowercase(*b)))
{ {
a++; a++;
b++; b++;
} }
return (unsigned char)fold(*a) - (unsigned char)fold(*b); return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
} }
int strncasecmp(const char* a, const char* b, size_t max) int strncasecmp(const char* a, const char* b, size_t max)
{ {
const char* base = a; const char* base = a;
while (*a && (fold(*a) == fold(*b)) && (size_t)(a - base) < (max - 1)) while (*a && (lowercase(*a) == lowercase(*b)) && (size_t)(a - base) < (max - 1))
{ {
a++; a++;
b++; b++;
} }
return (unsigned char)fold(*a) - (unsigned char)fold(*b); return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
} }
} }