Replace mh_xmalloc() with mh_xcalloc()
[mmh] / sbr / getcpy.c
1 /*
2 ** getcpy.c -- copy a string in managed memory
3 **
4 ** THIS IS OBSOLETE.  NEED TO REPLACE ALL OCCURENCES
5 ** OF GETCPY WITH STRDUP.  BUT THIS WILL REQUIRE
6 ** CHANGING PARTS OF THE CODE TO DEAL WITH NULL VALUES.
7 **
8 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
9 ** COPYRIGHT file in the root directory of the nmh distribution for
10 ** complete copyright information.
11 */
12
13 #include <h/mh.h>
14 #include <h/utils.h>
15
16
17 char *
18 getcpy(char *str)
19 {
20         char *cp;
21         size_t len;
22
23         if (str) {
24                 len = strlen(str) + 1;
25                 cp = mh_xcalloc(len, sizeof(char));
26                 memcpy(cp, str, len);
27         } else {
28                 cp = mh_xcalloc((size_t) 1, sizeof(char));
29                 *cp = '\0';
30         }
31         return cp;
32 }