X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Futils.c;h=ef0ee9738676d018b9c191f3d339cf89593b04ff;hp=f61456d6f8ebfde0857b1392dab49a94396a9065;hb=eb650f703c26232c0ccce00c9b3dd3f6b6d51dd4;hpb=d4c34b4439a9dbd89664de460ed37ecddc260fb1 diff --git a/sbr/utils.c b/sbr/utils.c index f61456d..ef0ee97 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -107,14 +107,14 @@ 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 ** -- 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; @@ -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; +}