2022-10-22 19:13:22 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
2022-11-06 13:45:58 +00:00
|
|
|
static char lowercase(char c)
|
2022-10-22 19:13:22 +00:00
|
|
|
{
|
2022-10-22 19:16:51 +00:00
|
|
|
if (isalpha(c)) return (char)tolower(c);
|
2022-10-22 19:13:22 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
void bzero(void* buf, size_t n)
|
|
|
|
{
|
|
|
|
memset(buf, 0, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bcopy(void* dest, const void* src, size_t n)
|
|
|
|
{
|
|
|
|
memcpy(dest, src, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int strcasecmp(const char* a, const char* b)
|
|
|
|
{
|
2022-11-06 13:45:58 +00:00
|
|
|
while (*a && (lowercase(*a) == lowercase(*b)))
|
2022-10-22 19:13:22 +00:00
|
|
|
{
|
|
|
|
a++;
|
|
|
|
b++;
|
|
|
|
}
|
2022-11-06 13:45:58 +00:00
|
|
|
return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
|
2022-10-22 19:13:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int strncasecmp(const char* a, const char* b, size_t max)
|
|
|
|
{
|
|
|
|
const char* base = a;
|
2022-11-06 13:45:58 +00:00
|
|
|
while (*a && (lowercase(*a) == lowercase(*b)) && (size_t)(a - base) < (max - 1))
|
2022-10-22 19:13:22 +00:00
|
|
|
{
|
|
|
|
a++;
|
|
|
|
b++;
|
|
|
|
}
|
2022-11-06 13:45:58 +00:00
|
|
|
return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
|
2022-10-22 19:13:22 +00:00
|
|
|
}
|
|
|
|
}
|