lib/libc: Add strdup() function
diff --git a/common/lib/libc.c b/common/lib/libc.c
index 1e654dda..d0a3de29 100644
--- a/common/lib/libc.c
+++ b/common/lib/libc.c
@@ -5,6 +5,7 @@
#include <string.h>
#include <lib/libc.h>
#include <lib/misc.h>
+#include <mm/pmm.h>
// Slightly adapted strtoul() implementation from FreeBSD.
// https://github.com/freebsd/freebsd-src/blob/de1aa3dab23c06fec962a14da3e7b4755c5880cf/lib/libc/stdlib/strtoul.c
@@ -121,3 +122,10 @@ char *strrchr(const char *str, int ch) {
return p;
}
+
+char *strdup(const char *s) {
+ size_t len = strlen(s) + 1;
+ char *buf = ext_mem_alloc(len);
+ memcpy(buf, s, len);
+ return buf;
+}
diff --git a/common/lib/libc.h b/common/lib/libc.h
index 66b9a950..2722e107 100644
--- a/common/lib/libc.h
+++ b/common/lib/libc.h
@@ -31,5 +31,6 @@ int strcasecmp(const char *, const char *);
int strncmp(const char *, const char *, size_t);
int strncasecmp(const char *, const char *, size_t);
int inet_pton(const char *src, void *dst);
+char *strdup(const char *);
#endif
