diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-05-03 13:48:50 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-12 07:59:59 +0200 |
commit | 15e26bb72b334da1830c26917e28ffcac64e8e4c (patch) | |
tree | c2d334fe86fb95e1b963172e349ea00a6249ad4f /lib/stringlist.c | |
parent | fab1f406fdb82f2876f48c3c9e33672c963809e2 (diff) | |
download | barebox-15e26bb72b334da1830c26917e28ffcac64e8e4c.tar.gz barebox-15e26bb72b334da1830c26917e28ffcac64e8e4c.tar.xz |
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 <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210503114901.13095-6-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/stringlist.c')
-rw-r--r-- | lib/stringlist.c | 30 |
1 files changed, 30 insertions, 0 deletions
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 <xfuncs.h> #include <malloc.h> #include <errno.h> +#include <string.h> #include <stringlist.h> 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; |