From 15e26bb72b334da1830c26917e28ffcac64e8e4c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 3 May 2021 13:48:50 +0200 Subject: param: introduce file-list parameter type DFU, fastboot and incoming mass storage support all use file lists as input, but individually check syntax correctness only on use. A dedicated file list parameter would improve the user experience and makes the code using it easier to handle: the struct file_list can be passed around directly instead of having to parse it first on use. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20210503114901.13095-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- lib/stringlist.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/stringlist.c') diff --git a/lib/stringlist.c b/lib/stringlist.c index 719fecdaa4..fc86640b94 100644 --- a/lib/stringlist.c +++ b/lib/stringlist.c @@ -2,6 +2,7 @@ #include #include #include +#include #include static int string_list_compare(struct list_head *a, struct list_head *b) @@ -95,6 +96,35 @@ int string_list_contains(struct string_list *sl, const char *str) return 0; } +char *string_list_join(const struct string_list *sl, const char *joinstr) +{ + struct string_list *entry; + size_t len = 0; + size_t joinstr_len = strlen(joinstr); + char *str, *next; + + string_list_for_each_entry(entry, sl) + len += strlen(entry->str) + joinstr_len; + + if (len == 0) + return strdup(""); + + str = malloc(len + 1); + if (!str) + return NULL; + + next = str; + + string_list_for_each_entry(entry, sl) { + next = stpcpy(next, entry->str); + next = stpcpy(next, joinstr); + } + + next[-joinstr_len] = '\0'; + + return str; +} + void string_list_print_by_column(struct string_list *sl) { int len = 0, num, i; -- cgit v1.2.3