summaryrefslogtreecommitdiffstats
path: root/newlib/libc/string/strndup_r.c
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-07-23 21:38:00 +0000
committerJeff Johnston <jjohnstn@redhat.com>2002-07-23 21:38:00 +0000
commitd254189b38bb5b0b77a18a401c05c415ce0733c9 (patch)
tree7a0a2dfa9e20a356bc0ba94eb20a26bef0c353d1 /newlib/libc/string/strndup_r.c
parent5e50e4e45c1f8758d431a6d881cd3da5572e8de7 (diff)
downloadcygnal-d254189b38bb5b0b77a18a401c05c415ce0733c9.tar.gz
cygnal-d254189b38bb5b0b77a18a401c05c415ce0733c9.tar.bz2
cygnal-d254189b38bb5b0b77a18a401c05c415ce0733c9.zip
2002-07-23 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/string.h: Add mempcpy, strndup, and _strndup_r prototypes. * libc/stdlib/Makefile.am: Remove strdup.c and strdup_r.c. * libc/stdlib/Makefile.in: Regenerated. * libc/stdlib/strdup.c: Removed. * libc/stdlib/strdup_r.c: Removed. * libc/string/Makefile.am: Add strdup.c, strdup_r.c, memccpy.c, mempcpy.c, strndup.c, and strndup_r.c. * libc/string/Makefile.in: Regenerated. * libc/string/memccpy.c: New file. * libc/string/mempcpy.c: Ditto. * libc/string/strndup.c: Ditto. * libc/string/strndup_r.c: Ditto. * libc/string/strdup.c: New file moved from stdlib. * libc/string/strdup_r.c: Ditto. * libc/string/strings.tex: Add memccpy and mempcpy documentation.
Diffstat (limited to 'newlib/libc/string/strndup_r.c')
-rw-r--r--newlib/libc/string/strndup_r.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/newlib/libc/string/strndup_r.c b/newlib/libc/string/strndup_r.c
new file mode 100644
index 000000000..86d9eec44
--- /dev/null
+++ b/newlib/libc/string/strndup_r.c
@@ -0,0 +1,21 @@
+#include <reent.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+char *
+_DEFUN (_strndup_r, (reent_ptr, str, n),
+ struct _reent *reent_ptr _AND
+ _CONST char *str _AND
+ size_t n)
+{
+ size_t len = MIN(strlen (str), n);
+ char *copy = _malloc_r (reent_ptr, len + 1);
+ if (copy)
+ {
+ memcpy (copy, str, len);
+ copy[len] = '\0';
+ }
+ return copy;
+}