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".
16 add (char *s2, char *s1)
19 size_t len1 = 0, len2 = 0;
27 if (!(cp = malloc (len1 + len2 + 1)))
28 adios (NULL, "unable to allocate string storage");
30 /* Copy s1 and free it */
32 memcpy (cp, s1, len1);
38 memcpy (cp + len1, s2, len2);
40 /* Now NULL terminate the string */
41 cp[len1 + len2] = '\0';