From 67a395794b678d7da053c3daf61eb12d3f9437f2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Nov 2017 14:44:35 +0100 Subject: Split into multiple units MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- strndup.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 strndup.c (limited to 'strndup.c') diff --git a/strndup.c b/strndup.c new file mode 100644 index 0000000..12c8006 --- /dev/null +++ b/strndup.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" + + +char * +libsimple_strndup(const char *s, size_t n) +{ + void *ret; + if (n == SIZE_MAX) { + errno = ENOMEM; + return NULL; + } + if (!(ret = malloc(n + 1))) + return NULL; + memcpy(ret, s, n); + ((char *)ret)[n] = '\0'; + return ret; +} -- cgit v1.2.3-70-g09d2