summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-06-03 15:05:07 -0400
committerJakob Kaivo <jkk@ung.org>2024-06-03 15:05:07 -0400
commit9c1836f093bf18db12eef6d437ee856b4c888c95 (patch)
treea4cb0ec858a7dc52f55a78d8016d8ae61a47f26b
parentd913ab781ed2426785b7ac2ebbbeaa50958a7f92 (diff)
add strdup() (and forced version) for tracking previous string values
-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;
+}