X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=string.c;fp=string.c;h=0b929688a2496d5a5f57c8a9e5590b17dd5d697a;hb=0a8f1be6ca96c7050f02129bb275c926671007f4;hp=87f9c265984d1a1b160b8bf784a273e417c46198;hpb=1f948aa655d9a7389477baa1489f86e548ec064e;p=adu.git diff --git a/string.c b/string.c index 87f9c26..0b92968 100644 --- a/string.c +++ b/string.c @@ -129,6 +129,34 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) return msg; } +/** + * adu's version of strcat(). + * + * \param a String to be appended to. + * \param b String to append. + * + * Append \p b to \p a. + * + * \return If \a a is \p NULL, return a pointer to a copy of \a b, i.e. + * para_strcat(NULL, b) is equivalent to para_strdup(b). If \a b is \p NULL, + * return \a a without making a copy of \a a. Otherwise, construct the + * concatenation \a c, free \a a (but not \a b) and return \a c. + * + * \sa strcat(3). + */ +__must_check __malloc char *adu_strcat(char *a, const char *b) +{ + char *tmp; + + if (!a) + return adu_strdup(b); + if (!b) + return a; + tmp = make_message("%s%s", a, b); + free(a); + return tmp; +} + /** \cond LLONG_MAX and LLONG_LIN might not be defined. */ #ifndef LLONG_MAX #define LLONG_MAX (1 << (sizeof(long) - 1))