From 667fc1d993cbaa566c4fc60fe3143846286de4c5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 16 Apr 2025 05:49:24 +0900 Subject: [PATCH] conf-files: use hashmap_dump_sorted() at one more place --- src/basic/conf-files.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 22d2bebe83e..85db567a5be 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -19,7 +19,6 @@ #include "nulstr-util.h" #include "path-util.h" #include "set.h" -#include "sort-util.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -122,29 +121,22 @@ static int files_add( return 0; } -static int base_cmp(char * const *a, char * const *b) { - assert(a); - assert(b); - return path_compare_filename(*a, *b); -} - static int copy_and_sort_files_from_hashmap(Hashmap *fh, char ***ret) { _cleanup_free_ char **sv = NULL; char **files; + int r; assert(ret); - sv = hashmap_get_strv(fh); - if (!sv) - return -ENOMEM; + r = hashmap_dump_sorted(fh, (void***) &sv, /* ret_n = */ NULL); + if (r < 0) + return r; - /* The entries in the array given by hashmap_get_strv() are still owned by the hashmap. */ + /* The entries in the array given by hashmap_dump_sorted() are still owned by the hashmap. */ files = strv_copy(sv); if (!files) return -ENOMEM; - typesafe_qsort(files, strv_length(files), base_cmp); - *ret = files; return 0; } @@ -237,7 +229,7 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p for (i = 0; i < n; i++) { int c; - c = base_cmp((char* const*) *strv + i, (char* const*) &path); + c = path_compare_filename((*strv)[i], path); if (c == 0) /* Oh, there already is an entry with a matching name (the last component). */ STRV_FOREACH(dir, dirs) { -- 2.47.3