diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-06-03 15:05:07 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-06-03 15:05:07 -0400 |
commit | 9c1836f093bf18db12eef6d437ee856b4c888c95 (patch) | |
tree | a4cb0ec858a7dc52f55a78d8016d8ae61a47f26b /src/string/strdup.c | |
parent | d913ab781ed2426785b7ac2ebbbeaa50958a7f92 (diff) |
add strdup() (and forced version) for tracking previous string values
Diffstat (limited to 'src/string/strdup.c')
-rw-r--r-- | src/string/strdup.c | 12 |
1 files changed, 12 insertions, 0 deletions
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; +} |