diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-07-30 11:46:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-08-08 15:13:31 +0200 |
commit | 2e9e7a400540c7f8cdc1466e81bff0efb5af8859 (patch) | |
tree | 430119b845e9fa1c534ba01c3637cd508f65a2a5 /common | |
parent | e99fe57ff127c84264a31c457846b833ee371361 (diff) | |
download | barebox-2e9e7a400540c7f8cdc1466e81bff0efb5af8859.tar.gz barebox-2e9e7a400540c7f8cdc1466e81bff0efb5af8859.tar.xz |
file_list: factor out file_list_new
We have the sequence for creating a new file_list at two places and
follow-up commit will add a third one outside of the file, so it's a
good occasion to use a common helper. No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220730094615.1762042-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/file-list.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/common/file-list.c b/common/file-list.c index 407b312833..11db7c6e44 100644 --- a/common/file-list.c +++ b/common/file-list.c @@ -130,16 +130,25 @@ static const char *flags_to_str(int flags) return str; } -struct file_list *file_list_parse(const char *str) +struct file_list *file_list_new(void) { struct file_list *files; - int ret; - const char *endptr; files = xzalloc(sizeof(*files)); INIT_LIST_HEAD(&files->list); + return files; +} + +struct file_list *file_list_parse(const char *str) +{ + struct file_list *files; + int ret; + const char *endptr; + + files = file_list_new(); + while (*str) { ret = file_list_parse_one(files, str, &endptr); if (ret) { @@ -195,9 +204,7 @@ struct file_list *file_list_dup(struct file_list *old) struct file_list_entry *old_entry; struct file_list *new; - new = xzalloc(sizeof(*new)); - - INIT_LIST_HEAD(&new->list); + new = file_list_new(); list_for_each_entry(old_entry, &old->list, list) { (void)file_list_add_entry(new, old_entry->name, old_entry->filename, |