3 * add.c -- If "s1" is NULL, this routine just creates a
4 * -- copy of "s2" into newly malloc'ed memory.
6 * -- If "s1" is not NULL, then copy the concatenation
7 * -- of "s1" and "s2" (note the order) into newly
8 * -- malloc'ed memory. Then free "s1".
12 * This code is Copyright (c) 2002, by the authors of nmh. See the
13 * COPYRIGHT file in the root directory of the nmh distribution for
14 * complete copyright information.
21 add (char *s2, char *s1)
24 size_t len1 = 0, len2 = 0;
32 cp = mh_xmalloc (len1 + len2 + 1);
34 /* Copy s1 and free it */
36 memcpy (cp, s1, len1);
42 memcpy (cp + len1, s2, len2);
44 /* Now NULL terminate the string */
45 cp[len1 + len2] = '\0';