OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [string/] [strndup_r.c] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#include <reent.h>
2
#include <stdlib.h>
3
#include <string.h>
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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.