Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/strdup.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
     1/*
     2
     3@deftypefn Supplemental char* strdup (const char *@var{s})
     4
     5Returns 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
     19extern size_t   strlen PARAMS ((const char*));
     20extern PTR      malloc PARAMS ((size_t));
     21extern PTR      memcpy PARAMS ((PTR, const PTR, size_t));
     22
    123char *
    224strdup(s)
    325     char *s;
    426{
    5     char *result = (char*)malloc(strlen(s) + 1);
    6     if (result == (char*)0)
    7         return (char*)0;
    8     strcpy(result, s);
    9     return result;
     27  size_t len = strlen (s) + 1;
     28  char *result = (char*) malloc (len);
     29  if (result == (char*) 0)
     30    return (char*) 0;
     31  return (char*) memcpy (result, s, len);
    1032}
Note: See TracChangeset for help on using the changeset viewer.