From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/string/strndup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/string/strndup.c (limited to 'src/string/strndup.c') diff --git a/src/string/strndup.c b/src/string/strndup.c new file mode 100644 index 00000000..617d27ba --- /dev/null +++ b/src/string/strndup.c @@ -0,0 +1,12 @@ +#include +#include + +char *strndup(const char *s, size_t n) +{ + size_t l = strnlen(s, n); + char *d = malloc(l+1); + if (!d) return NULL; + memcpy(d, s, l); + d[l] = 0; + return d; +} -- cgit v1.2.1