]> diplodocus.org Git - nmh/blob - sbr/getcpy.c
Fix stupid accidental dependence on a bash quirk in previous
[nmh] / sbr / getcpy.c
1
2 /*
3 * getcpy.c -- copy a string in managed memory
4 *
5 * THIS IS OBSOLETE. NEED TO REPLACE ALL OCCURENCES
6 * OF GETCPY WITH STRDUP. BUT THIS WILL REQUIRE
7 * CHANGING PARTS OF THE CODE TO DEAL WITH NULL VALUES.
8 *
9 * $Id$
10 *
11 * This code is Copyright (c) 2002, by the authors of nmh. See the
12 * COPYRIGHT file in the root directory of the nmh distribution for
13 * complete copyright information.
14 */
15
16 #include <h/mh.h>
17
18
19 char *
20 getcpy (char *str)
21 {
22 char *cp;
23 size_t len;
24
25 if (str) {
26 len = strlen(str) + 1;
27 if (!(cp = malloc (len)))
28 adios (NULL, "unable to allocate string storage");
29 memcpy (cp, str, len);
30 } else {
31 if (!(cp = malloc ((size_t) 1)))
32 adios (NULL, "unable to allocate string storage");
33 *cp = '\0';
34 }
35 return cp;
36 }