summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/strdup.c
blob: 88a2b3e0fc05aa8be890774d32550a5d9fd5ebfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
**  Portable, public domain strdup() by Bob Stout
*/

#include <stdlib.h>
#include <string.h>

char *strdup(const char *string)
{
      char *new;

      if (NULL != (new = malloc(strlen(string) + 1)))
            strcpy(new, string);
      return new;
}