]> diplodocus.org Git - nmh/blob - sbr/getcpy.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[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
12 #include <h/mh.h>
13
14
15 char *
16 getcpy (char *str)
17 {
18 char *cp;
19 size_t len;
20
21 if (str) {
22 len = strlen(str) + 1;
23 if (!(cp = malloc (len)))
24 adios (NULL, "unable to allocate string storage");
25 memcpy (cp, str, len);
26 } else {
27 if (!(cp = malloc ((size_t) 1)))
28 adios (NULL, "unable to allocate string storage");
29 *cp = '\0';
30 }
31 return cp;
32 }