Luna/libs/libc/src/strings.cpp

43 lines
912 B
C++
Raw Normal View History

2022-10-22 19:13:22 +00:00
#include <ctype.h>
#include <string.h>
#include <strings.h>
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)
{
while (*a && (lowercase(*a) == lowercase(*b)))
2022-10-22 19:13:22 +00:00
{
a++;
b++;
}
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;
while (*a && (lowercase(*a) == lowercase(*b)) && (size_t)(a - base) < (max - 1))
2022-10-22 19:13:22 +00:00
{
a++;
b++;
}
return (unsigned char)lowercase(*a) - (unsigned char)lowercase(*b);
2022-10-22 19:13:22 +00:00
}
}