fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / strndup_r.c
blob86d9eec44019fa9d2b5ef2bb715bf754895fb61a
1 #include <reent.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #define MIN(a,b) ((a) < (b) ? (a) : (b))
7 char *
8 _DEFUN (_strndup_r, (reent_ptr, str, n),
9 struct _reent *reent_ptr _AND
10 _CONST char *str _AND
11 size_t n)
13 size_t len = MIN(strlen (str), n);
14 char *copy = _malloc_r (reent_ptr, len + 1);
15 if (copy)
17 memcpy (copy, str, len);
18 copy[len] = '\0';
20 return copy;