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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [libiberty/] [strdup.c] - Blame information for rev 301

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

Line No. Rev Author Line
1 205 julius
/*
2
 
3
@deftypefn Supplemental char* strdup (const char *@var{s})
4
 
5
Returns a pointer to a copy of @var{s} in memory obtained from
6
@code{malloc}, or @code{NULL} if insufficient memory was available.
7
 
8
@end deftypefn
9
 
10
*/
11
 
12
#include <ansidecl.h>
13
#include <stddef.h>
14
 
15
extern size_t   strlen (const char*);
16
extern PTR      malloc (size_t);
17
extern PTR      memcpy (PTR, const PTR, size_t);
18
 
19
char *
20
strdup(const char *s)
21
{
22
  size_t len = strlen (s) + 1;
23
  char *result = (char*) malloc (len);
24
  if (result == (char*) 0)
25
    return (char*) 0;
26
  return (char*) memcpy (result, s, len);
27
}

powered by: WebSVN 2.1.0

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