Subversion Repositories Kolibri OS

Rev

Rev 4872 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
#include 
2
#include 
3
#include 
4
 
5
char *
6
_DEFUN (_strndup_r, (reent_ptr, str, n),
7
        struct _reent *reent_ptr  _AND
8
        _CONST char   *str _AND
9
        size_t n)
10
{
11
  _CONST char *ptr = str;
12
  size_t len;
13
  char *copy;
14
 
15
  while (n-- > 0 && *ptr)
16
    ptr++;
17
 
18
  len = ptr - str;
19
 
20
  copy = _malloc_r (reent_ptr, len + 1);
21
  if (copy)
22
    {
23
      memcpy (copy, str, len);
24
      copy[len] = '\0';
25
    }
26
  return copy;
27
}