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