common: move append_str to string-utils
[lttng-tools.git] / src / common / string-utils / string-utils.c
index 669f7d05fd01c64513b68128a740c8940fdcaa9d..526604d14e42a6f0d907fab86676ca2f2435e46f 100644 (file)
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <assert.h>
+#include <errno.h>
 
 #include "string-utils.h"
 #include "../macros.h"
@@ -370,3 +371,24 @@ size_t strutils_array_of_strings_len(char * const *array)
 
        return count;
 }
+
+LTTNG_HIDDEN
+int strutils_append_str(char **s, const char *append)
+{
+       char *old = *s;
+       char *new;
+       size_t oldlen = (old == NULL) ? 0 : strlen(old);
+       size_t appendlen = strlen(append);
+
+       new = calloc(oldlen + appendlen + 1, 1);
+       if (!new) {
+               return -ENOMEM;
+       }
+       if (oldlen) {
+               strcpy(new, old);
+       }
+       strcat(new, append);
+       *s = new;
+       free(old);
+       return 0;
+}
This page took 0.023295 seconds and 4 git commands to generate.