43 lines
912 B
C++
43 lines
912 B
C++
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
|
|
static char lowercase(char c)
|
|
{
|
|
if (isalpha(c)) return (char)tolower(c);
|
|
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)
|
|
{
|
|
while (*a && (lowercase(*a) == lowercase(*b)))
|
|
{
|
|
a++;
|
|
b++;
|
|
}
|
|
return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
|
|
}
|
|
|
|
int strncasecmp(const char* a, const char* b, size_t max)
|
|
{
|
|
const char* base = a;
|
|
while (*a && (lowercase(*a) == lowercase(*b)) && (size_t)(a - base) < (max - 1))
|
|
{
|
|
a++;
|
|
b++;
|
|
}
|
|
return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
|
|
}
|
|
} |