diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-08 05:02:56 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-08 05:08:51 +0900 |
commit | 1a39bddfbb0c233ade94a1d51755c42db3ece552 (patch) | |
tree | 13e4cff4735d2c959fc95f1fd736bc5f3c2356b1 /src/basic/conf-files.c | |
parent | 273426750aad94d79aec142b3e11eb7eb143f73c (diff) | |
download | systemd-1a39bddfbb0c233ade94a1d51755c42db3ece552.tar.gz |
conf-files: split out logic of copy and sort filenames from hashmap
No functional change, preparation for the next commit.
Diffstat (limited to 'src/basic/conf-files.c')
-rw-r--r-- | src/basic/conf-files.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 2fb7ffa926..9e7428a3c8 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -125,6 +125,27 @@ static int base_cmp(char * const *a, char * const *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; + + assert(ret); + + sv = hashmap_get_strv(fh); + if (!sv) + return -ENOMEM; + + /* The entries in the array given by hashmap_get_strv() 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; +} + int conf_files_list_strv( char ***ret, const char *suffix, @@ -134,8 +155,6 @@ int conf_files_list_strv( _cleanup_hashmap_free_ Hashmap *fh = NULL; _cleanup_set_free_ Set *masked = NULL; - _cleanup_strv_free_ char **files = NULL; - _cleanup_free_ char **sv = NULL; int r; assert(ret); @@ -158,19 +177,7 @@ int conf_files_list_strv( log_debug_errno(r, "Failed to search for files in '%s', ignoring: %m", path); } - sv = hashmap_get_strv(fh); - if (!sv) - return -ENOMEM; - - /* The entries in the array given by hashmap_get_strv() are still owned by the hashmap. */ - files = strv_copy(sv); - if (!files) - return -ENOMEM; - - typesafe_qsort(files, strv_length(files), base_cmp); - *ret = TAKE_PTR(files); - - return 0; + return copy_and_sort_files_from_hashmap(fh, ret); } int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path) { |