1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

Kernel: Add memchr and malloc to StdLib.cpp

These are needed by `libcxxabi`'s demangle support. `memchr` is taken
straight-up from the `LibC/string.cpp` source code.
This commit is contained in:
Daniel Bertalan 2021-07-05 20:09:01 +02:00 committed by Gunnar Beutner
parent 6f6b1b3ea1
commit 494ead3eb8

View file

@ -396,6 +396,22 @@ char* strstr(const char* haystack, const char* needle)
return const_cast<char*>(haystack);
}
void* memchr(const void* ptr, int c, size_t size)
{
char ch = c;
auto* cptr = (const char*)ptr;
for (size_t i = 0; i < size; ++i) {
if (cptr[i] == ch)
return const_cast<char*>(cptr + i);
}
return nullptr;
}
void* malloc(size_t s)
{
return kmalloc(s);
}
void* realloc(void* p, size_t s)
{
return krealloc(p, s);