X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Futils.c;h=466b9aba2627e7c4f1e6d9d384e2ca69e83063e4;hp=f61456d6f8ebfde0857b1392dab49a94396a9065;hb=9cf6132a6ea29968131a000bc2fb6860affac45e;hpb=d4c34b4439a9dbd89664de460ed37ecddc260fb1 diff --git a/sbr/utils.c b/sbr/utils.c index f61456d..466b9ab 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -107,7 +107,7 @@ pwd(void) /* ** 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 @@ -218,3 +218,19 @@ app_msgarg(struct msgs_array *msgs, char *cp) } 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; +}