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/_forced/strdup.h | 2 ++ src/string/strdup.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/_forced/strdup.h create mode 100644 src/string/strdup.c 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 +#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