LibC: Implement non-locale specific functions from strings.h
This commit is contained in:
parent
694cda6e40
commit
8216d09e06
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue