From 9c1836f093bf18db12eef6d437ee856b4c888c95 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 3 Jun 2024 15:05:07 -0400 Subject: add strdup() (and forced version) for tracking previous string values --- src/string/strdup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/string/strdup.c (limited to 'src/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 +#include +#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; +} -- cgit v1.2.1