Browse Source

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.
Daniel Bertalan 4 years ago
parent
commit
494ead3eb8
1 changed files with 16 additions and 0 deletions
  1. 16 0
      Kernel/StdLib.cpp

+ 16 - 0
Kernel/StdLib.cpp

@@ -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);