1 /* 2 Copyright (c) 2002 Jeff Johnston <jjohnstn@redhat.com> 3 */ 4 #include <stdlib.h> 5 #include <string.h> 6 7 char * _strndup_r(struct _reent * reent_ptr,const char * str,size_t n)8_strndup_r (struct _reent *reent_ptr, 9 const char *str, 10 size_t n) 11 { 12 const char *ptr = str; 13 size_t len; 14 char *copy; 15 16 while (n-- > 0 && *ptr) 17 ptr++; 18 19 len = ptr - str; 20 21 copy = _malloc_r (reent_ptr, len + 1); 22 if (copy) 23 { 24 memcpy (copy, str, len); 25 copy[len] = '\0'; 26 } 27 return copy; 28 } 29