summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-07-28 11:28:13 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-08-03 13:54:38 -0400
commitdae0af263a9490c57962c2d43ede2083d618e637 (patch)
treefb1924a83f621134dda451ff00b926c020b13294
parent0228e28a3f07b5dc909cdc154dc89c4952f09280 (diff)
downloadsssd-dae0af263a9490c57962c2d43ede2083d618e637.tar.gz
sssd-dae0af263a9490c57962c2d43ede2083d618e637.tar.xz
sssd-dae0af263a9490c57962c2d43ede2083d618e637.zip
Add dup_string_list() utility function
-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 206984c..10bfb64 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 da92ae6..6bcc998 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.