X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fstring-utils%2Fstring-utils.c;h=526604d14e42a6f0d907fab86676ca2f2435e46f;hb=5b770521bbf951df78c52ea4c2b7cf9e0dc1bd5e;hp=669f7d05fd01c64513b68128a740c8940fdcaa9d;hpb=e9afa78ade64ab725959e934a55165fc81f37380;p=lttng-tools.git diff --git a/src/common/string-utils/string-utils.c b/src/common/string-utils/string-utils.c index 669f7d05f..526604d14 100644 --- a/src/common/string-utils/string-utils.c +++ b/src/common/string-utils/string-utils.c @@ -10,6 +10,7 @@ #include #include #include +#include #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; +}