summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/util/util.c31
-rw-r--r--src/util/util.h6
2 files changed, 37 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c
index 206984c7a..10bfb647b 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -237,7 +237,38 @@ fail:
return NULL;
}
+char **dup_string_list(TALLOC_CTX *memctx, const char **str_list)
+{
+ int i = 0;
+ int j = 0;
+ char **dup_list;
+
+ if (!str_list) {
+ return NULL;
+ }
+
+ /* Find the size of the list */
+ while (str_list[i]) i++;
+
+ dup_list = talloc_array(memctx, char *, i+1);
+ if (!dup_list) {
+ return NULL;
+ }
+ /* Copy the elements */
+ for (j = 0; j < i; j++) {
+ dup_list[j] = talloc_strdup(dup_list, str_list[j]);
+ if (!dup_list[j]) {
+ talloc_free(dup_list);
+ return NULL;
+ }
+ }
+
+ /* NULL-terminate the list */
+ dup_list[i] = NULL;
+
+ return dup_list;
+}
/* Take two string lists (terminated on a NULL char*)
* and return up to three arrays of strings based on
diff --git a/src/util/util.h b/src/util/util.h
index da92ae68c..6bcc9984d 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -332,6 +332,12 @@ int split_on_separator(TALLOC_CTX *mem_ctx, const char *str,
char **parse_args(const char *str);
+
+/* Copy a NULL-terminated string list
+ * Returns NULL on out of memory error or invalid input
+ */
+char **dup_string_list(TALLOC_CTX *memctx, const char **str_list);
+
/* Take two string lists (terminated on a NULL char*)
* and return up to three arrays of strings based on
* shared ownership.