Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / strndup_r.c
blob1b6cf84e583764836aeeeae3eff9573c098d3ca1
1 #include <reent.h>
2 #include <stdlib.h>
3 #include <string.h>
5 char *
6 _strndup_r (struct _reent *reent_ptr,
7 const char *str,
8 size_t n)
10 const char *ptr = str;
11 size_t len;
12 char *copy;
14 while (n-- > 0 && *ptr)
15 ptr++;
17 len = ptr - str;
19 copy = _malloc_r (reent_ptr, len + 1);
20 if (copy)
22 memcpy (copy, str, len);
23 copy[len] = '\0';
25 return copy;