LibC: Implement non-locale specific functions from strings.h

This commit is contained in:
Bananymous 2023-12-14 10:59:39 +02:00
parent 694cda6e40
commit 8216d09e06
2 changed files with 31 additions and 0 deletions

View File

@ -14,6 +14,7 @@ set(LIBC_SOURCES
stdio.cpp stdio.cpp
stdlib.cpp stdlib.cpp
string.cpp string.cpp
strings.cpp
sys/banan-os.cpp sys/banan-os.cpp
sys/mman.cpp sys/mman.cpp
sys/stat.cpp sys/stat.cpp

30
libc/strings.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <ctype.h>
#include <strings.h>
int ffs(int i)
{
for (unsigned idx = 0; idx < sizeof(i) * 8; idx++)
if (i & (1 << idx))
return i + 1;
return 0;
}
int strcasecmp(const char* s1, const char* s2)
{
const unsigned char* u1 = (unsigned char*)s1;
const unsigned char* u2 = (unsigned char*)s2;
for (; *u1 && *u2; u1++, u2++)
if (tolower(*u1) != tolower(*u2))
break;
return tolower(*u1) - tolower(*u2);
}
int strncasecmp(const char* s1, const char* s2, size_t n)
{
const unsigned char* u1 = (unsigned char*)s1;
const unsigned char* u2 = (unsigned char*)s2;
for (; --n && *u1 && *u2; u1++, u2++)
if (tolower(*u1) != tolower(*u2))
break;
return tolower(*u1) - tolower(*u2);
}