* patch #3966: Create a mh_xmalloc function to prevent mistakes when
[mmh] / sbr / strdup.c
1
2 /*
3  * strdup.c -- duplicate a string
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2002, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/mh.h>
13 #include <h/utils.h>
14
15
16 char *
17 strdup (const char *str)
18 {
19     char *cp;
20     size_t len;
21
22     if (!str)
23         return NULL;
24
25     len = strlen(str) + 1;
26     cp = mh_xmalloc (len);
27     memcpy (cp, str, len);
28     return cp;
29 }