common: move append_str to string-utils
[lttng-tools.git] / src / common / string-utils / string-utils.cpp
index 3051644f34adf1a77853a7c63e2d3096318b6ff0..8dcc6b2aae9ce9fab7b3beeefbea0b495fc15db4 100644 (file)
@@ -10,6 +10,8 @@
 #include <string.h>
 #include <stdbool.h>
 #include <type_traits>
 #include <string.h>
 #include <stdbool.h>
 #include <type_traits>
+#include <assert.h>
+#include <errno.h>
 
 #include "string-utils.h"
 #include "../macros.h"
 
 #include "string-utils.h"
 #include "../macros.h"
@@ -373,3 +375,23 @@ size_t strutils_array_of_strings_len(char * const *array)
 
        return count;
 }
 
        return count;
 }
+
+int strutils_append_str(char **s, const char *append)
+{
+       char *old = *s;
+       char *new_str;
+       size_t oldlen = (old == NULL) ? 0 : strlen(old);
+       size_t appendlen = strlen(append);
+
+       new_str = (char *) zmalloc(oldlen + appendlen + 1);
+       if (!new_str) {
+               return -ENOMEM;
+       }
+       if (oldlen) {
+               strcpy(new_str, old);
+       }
+       strcat(new_str, append);
+       *s = new_str;
+       free(old);
+       return 0;
+}
This page took 0.023437 seconds and 4 git commands to generate.