]> git.tuebingen.mpg.de Git - adu.git/blobdiff - string.c
Add pretty-printing formating functions.
[adu.git] / string.c
index 87f9c265984d1a1b160b8bf784a273e417c46198..0b929688a2496d5a5f57c8a9e5590b17dd5d697a 100644 (file)
--- 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))