From 06805e9ec8db3cffeead4c64a211fd6692cd6cab Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 15 Oct 2025 15:11:25 +0200 Subject: [PATCH] lib/configs: add head parameter to configs_refer_filename() Allow configs_refer_filename() to add entries at either the head or tail of the list by adding a 'head' parameter. This simplifies the code for adding the main config file, eliminating the need to add to the tail and then move to the head. When head=1, use list_add() to prepend to the list. When head=0, use list_add_tail() to append to the list. Signed-off-by: Karel Zak --- lib/configs.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/configs.c b/lib/configs.c index a7faf6ad2..7ecd69df6 100644 --- a/lib/configs.c +++ b/lib/configs.c @@ -74,7 +74,7 @@ static char *main_configs(const char *root, return path; } -static int configs_refer_filename(struct list_head *list, char *filename) +static int configs_refer_filename(struct list_head *list, char *filename, int head) { struct file_element *e; @@ -84,7 +84,10 @@ static int configs_refer_filename(struct list_head *list, char *filename) INIT_LIST_HEAD(&e->file_list); e->filename = filename; - list_add_tail(&e->file_list, list); + if (head) + list_add(&e->file_list, list); + else + list_add_tail(&e->file_list, list); return 0; } @@ -147,7 +150,7 @@ static int read_dir(struct list_head *file_list, break; } - ret = configs_refer_filename(file_list, filename); + ret = configs_refer_filename(file_list, filename, 0); if (ret < 0) { free(filename); break; @@ -285,18 +288,11 @@ int ul_configs_file_list(struct list_head *file_list, /* Add main config file at the beginning (highest priority) */ if (main_file != NULL) { - struct list_head *e; - - ret = configs_refer_filename(file_list, main_file); + ret = configs_refer_filename(file_list, main_file, 1); if (ret < 0) { free(main_file); goto finish; } - - /* Move last element (just added) to front */ - e = file_list->prev; - list_del(e); - list_add(e, file_list); } counter = list_count_entries(file_list); -- 2.47.3