From 9710d39e0de75ca5fd5a5d9c6de4fe4efba31790 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 27 Sep 2017 12:22:59 +0200 Subject: file_list: Allow only unique names on list The key to a file_list is it's name, so ensure it's unique. Signed-off-by: Sascha Hauer --- common/file-list.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/file-list.c b/common/file-list.c index 0b760c1aec..e13d5af659 100644 --- a/common/file-list.c +++ b/common/file-list.c @@ -23,7 +23,13 @@ struct file_list_entry *file_list_entry_by_name(struct file_list *files, const c int file_list_add_entry(struct file_list *files, const char *name, const char *filename, unsigned long flags) { - struct file_list_entry *entry = xzalloc(sizeof(*entry)); + struct file_list_entry *entry; + + entry = file_list_entry_by_name(files, name); + if (entry) + return -EEXIST; + + entry = xzalloc(sizeof(*entry)); entry->name = xstrdup(name); entry->filename = xstrdup(filename); -- cgit v1.2.3