summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/_forced/strdup.h2
-rw-r--r--src/string/strdup.c12
2 files changed, 14 insertions, 0 deletions
diff --git a/src/_forced/strdup.h b/src/_forced/strdup.h
new file mode 100644
index 00000000..5abd92ce
--- /dev/null
+++ b/src/_forced/strdup.h
@@ -0,0 +1,2 @@
+static char *strdup(const char *);
+#include "string/strdup.c"
diff --git a/src/string/strdup.c b/src/string/strdup.c
new file mode 100644
index 00000000..9780deaa
--- /dev/null
+++ b/src/string/strdup.c
@@ -0,0 +1,12 @@
+#include <string.h>
+#include <stdlib.h>
+#include "_safety.h"
+
+char *strdup(const char *s)
+{
+ ASSERT_NONNULL(s);
+ size_t len = strlen(s) + 1;
+ char *dup = malloc(len);
+ memcpy(dup, s, len);
+ return dup;
+}