/*
** add -- If "s1" is NULL, this routine just creates a
** -- copy of "s2" into newly malloc'ed memory.
-** -- (use getcpy() instead in this case)
+** -- (use mh_xstrdup() instead in this case)
** --
** -- If "s1" is not NULL, then copy the concatenation
** -- of "s1" and "s2" (note the order) into newly
** -- malloc'ed memory. Then free "s1".
*/
char *
-add(char *s2, char *s1)
+add(const char *s2, char *s1)
{
char *cp;
size_t len1 = 0, len2 = 0;
}
msgs->msgs[msgs->size++] = cp;
}
+
+/*
+** mh_xstrdup() is a wrapper of strdup() to replace getcpy(). It returns
+** a copy of its argument if this is nonnull; otherwise, it returns a
+** string of length 0.
+*/
+char *
+mh_xstrdup(char * s)
+{
+ char * tmp;
+ tmp = strdup(s ? s : "");
+ if (!tmp) {
+ adios(EX_OSERR, "strdup", "can't copy string");
+ }
+ return tmp;
+}