X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Futils.c;h=50060ae7c42b2a4faa7bb64a863030a84cdde1cf;hp=f61456d6f8ebfde0857b1392dab49a94396a9065;hb=a4ff68e851c0931ced437f73a1acb0fedb28bec3;hpb=d4c34b4439a9dbd89664de460ed37ecddc260fb1 diff --git a/sbr/utils.c b/sbr/utils.c index f61456d..50060ae 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(const char * s) +{ + char * tmp; + tmp = strdup(s ? s : ""); + if (!tmp) { + adios(EX_OSERR, "strdup", "can't copy string"); + } + return tmp; +}