/[gnats]/gnats/libiberty/strdup.c
ViewVC logotype

Diff of /gnats/libiberty/strdup.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by brendan, Thu Nov 5 19:54:16 1998 UTC revision 1.2 by chewie, Sat Nov 13 05:14:17 2004 UTC
# Line 1  Line 1 
1    /*
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    #ifdef ANSI_PROTOTYPES
14    #include <stddef.h>
15    #else
16    #define size_t unsigned long
17    #endif
18    
19    extern size_t   strlen PARAMS ((const char*));
20    extern PTR      malloc PARAMS ((size_t));
21    extern PTR      memcpy PARAMS ((PTR, const PTR, size_t));
22    
23  char *  char *
24  strdup(s)  strdup(s)
25       char *s;       const char *s;
26  {  {
27      char *result = (char*)malloc(strlen(s) + 1);    size_t len = strlen (s) + 1;
28      if (result == (char*)0)    char *result = (char*) malloc (len);
29          return (char*)0;    if (result == (char*) 0)
30      strcpy(result, s);      return (char*) 0;
31      return result;    return (char*) memcpy (result, s, len);
32  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26