summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/string.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/string.c b/src/core/string.c
index 8577215be..2e17bdcb0 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -333,6 +333,21 @@ void * memchr(const void *s, int c, size_t n)
#endif
+char * strndup(const char *s, size_t n)
+{
+ size_t len = strlen(s);
+ char *new;
+
+ if (len>n)
+ len = n;
+ new = malloc(len+1);
+ if (new) {
+ new[len] = '\0';
+ memcpy(new,s,len);
+ }
+ return new;
+}
+
char * strdup(const char *s) {
return strndup(s, ~((size_t)0));
}