summaryrefslogtreecommitdiff
path: root/libc/string/string.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-10-11 08:36:33 +0000
committerEric Andersen <andersen@codepoet.org>2001-10-11 08:36:33 +0000
commitbef22c1887f4b984969e2e2b5082bd42a16d661a (patch)
tree27cc61bfeff53df874be62939706ed69c9f53cf2 /libc/string/string.c
parent5c12c8eecd5f2e06c200651e90befe85efcf166f (diff)
Add strndup, written by Stefan Soucek <ssoucek@coactive.com>
Diffstat (limited to 'libc/string/string.c')
-rw-r--r--libc/string/string.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/libc/string/string.c b/libc/string/string.c
index 7ccc55733..94bf542e4 100644
--- a/libc/string/string.c
+++ b/libc/string/string.c
@@ -274,6 +274,25 @@ char *strdup(const char *str)
}
#endif
+/********************** Function strndup ************************************/
+#ifdef L_strndup
+char *strndup(const char *str, size_t len)
+{
+ register size_t n;
+ register char *dst;
+
+ n = strlen(str);
+ if (len < n)
+ n = len;
+ dst = (char *) malloc(n+1);
+ if (dst) {
+ memcpy(dst, str, n);
+ dst[n] = '\0';
+ }
+ return dst;
+}
+#endif
+
/********************** Function memcpy ************************************/
#ifdef L_memcpy
@@ -409,5 +428,4 @@ int ffs(int x)
}
#endif
-
/********************** THE END ********************************************/