[PATCH 03/12] file_list: Allow only unique names on list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The key to a file_list is it's name, so ensure it's unique.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 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);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux