summaryrefslogtreecommitdiff
path: root/LibC
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-26 13:32:13 +0200
committerAndreas Kling <awesomekling@gmail.com>2018-10-26 13:32:13 +0200
commitac738b03d6b87972e54ddd225f3a7741e5781d77 (patch)
treed032c68ea2ff7c78ba6895a0af2dc6646878facd /LibC
parent0af9254812cb560109ccc6fec2e9c3077e3338fc (diff)
downloadserenity-ac738b03d6b87972e54ddd225f3a7741e5781d77.zip
Add memcpy() and strcmp() to LibC.
Diffstat (limited to 'LibC')
-rw-r--r--LibC/string.cpp17
-rw-r--r--LibC/string.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/LibC/string.cpp b/LibC/string.cpp
index 06e28676e4..82877ec401 100644
--- a/LibC/string.cpp
+++ b/LibC/string.cpp
@@ -12,6 +12,23 @@ size_t strlen(const char* str)
return len;
}
+int strcmp(const char* s1, const char* s2)
+{
+ for (; *s1 == *s2; ++s1, ++s2) {
+ if (*s1 == 0)
+ return 0;
+ }
+ return *(const unsigned char*)s1 < *(const unsigned char*)s2 ? -1 : 1;
+}
+
+void memcpy(void* dest, const void* src, size_t n)
+{
+ auto* bdest = (unsigned char*)dest;
+ auto* bsrc = (const unsigned char*)src;
+ for (; n; --n)
+ *(bdest++) = *(bsrc++);
+}
+
const char* strerror(int errnum)
{
switch (errnum) {
diff --git a/LibC/string.h b/LibC/string.h
index 15d0dbf1bf..32444fd90d 100644
--- a/LibC/string.h
+++ b/LibC/string.h
@@ -5,6 +5,8 @@
extern "C" {
size_t strlen(const char*);
+int strcmp(const char*, const char*);
+void memcpy(void*, const void*, size_t);
const char* strerror(int errnum);
}