summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2012-05-07 13:20:29 +0200
committerKay Sievers <kay@vrfy.org>2012-05-07 13:20:29 +0200
commit0a1a17aa2d9112470124ef5afb9314343777dc29 (patch)
tree414415282b8c18ab577d7dbfadc10a76328e2186 /src/shared/util.c
parentcd9556cc84523e2d515a8be2648e2a50fb6b2144 (diff)
conf_files_list(): split out conf_files_list_strv()
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index d86df17591..2bfa2cb4e6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4915,29 +4915,13 @@ static int base_cmp(const void *a, const void *b) {
return strcmp(file_name_from_path(s1), file_name_from_path(s2));
}
-int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) {
Hashmap *fh = NULL;
- char **dirs = NULL;
char **files = NULL;
- char **p;
- va_list ap;
+ const char **p;
int r = 0;
- va_start(ap, dir);
- dirs = strv_new_ap(dir, ap);
- va_end(ap);
- if (!dirs) {
- r = -ENOMEM;
- goto finish;
- }
- if (!strv_path_canonicalize(dirs)) {
- r = -ENOMEM;
- goto finish;
- }
- if (!strv_uniq(dirs)) {
- r = -ENOMEM;
- goto finish;
- }
+ assert(dirs);
fh = hashmap_new(string_hash_func, string_compare_func);
if (!fh) {
@@ -4959,16 +4943,40 @@ int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
r = -ENOMEM;
goto finish;
}
-
qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
finish:
- strv_free(dirs);
hashmap_free(fh);
*strv = files;
return r;
}
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+ char **dirs = NULL;
+ va_list ap;
+ int r;
+
+ va_start(ap, dir);
+ dirs = strv_new_ap(dir, ap);
+ va_end(ap);
+ if (!dirs) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (!strv_path_canonicalize(dirs)) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ strv_uniq(dirs);
+
+ r = conf_files_list_strv(strv, suffix, (const char **)dirs);
+
+finish:
+ strv_free(dirs);
+ return r;
+}
+
int hwclock_is_localtime(void) {
FILE *f;
bool local = false;