return 0;
}
-int conf_files_insert(char ***strv, const char *root, const char *dirs, const char *path) {
+int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path) {
/* Insert a path into strv, at the place honouring the usual sorting rules:
* - we first compare by the basename
* - and then we compare by dirname, allowing just one file with the given
c = base_cmp(*strv + i, &path);
if (c == 0) {
- const char *dir;
+ char **dir;
/* Oh, we found our spot and it already contains something. */
- NULSTR_FOREACH(dir, dirs) {
+ STRV_FOREACH(dir, dirs) {
char *p1, *p2;
p1 = path_startswith((*strv)[i], root);
if (p1)
- /* Skip "/" in dir, because p1 is without "/" too */
- p1 = path_startswith(p1, dir + 1);
+ /* Skip "/" in *dir, because p1 is without "/" too */
+ p1 = path_startswith(p1, *dir + 1);
if (p1)
/* Existing entry with higher priority
* or same priority, no need to do anything. */
return 0;
- p2 = path_startswith(path, dir);
+ p2 = path_startswith(path, *dir);
if (p2) {
/* Our new entry has higher priority */
t = path_join(root, path, NULL);
return r;
}
+int conf_files_insert_nulstr(char ***strv, const char *root, const char *dirs, const char *path) {
+ _cleanup_strv_free_ char **d = NULL;
+
+ assert(strv);
+
+ d = strv_split_nulstr(dirs);
+ if (!d)
+ return -ENOMEM;
+
+ return conf_files_insert(strv, root, d, path);
+}
+
int conf_files_list_strv(char ***strv, const char *suffix, const char *root, unsigned flags, const char* const* dirs) {
_cleanup_strv_free_ char **copy = NULL;
return conf_files_list_strv_internal(strv, suffix, root, flags, dirs);
}
-int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, unsigned flags, const char *d) {
- _cleanup_strv_free_ char **dirs = NULL;
+int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dirs) {
+ _cleanup_strv_free_ char **d = NULL;
assert(strv);
- dirs = strv_split_nulstr(d);
- if (!dirs)
+ d = strv_split_nulstr(dirs);
+ if (!d)
return -ENOMEM;
- return conf_files_list_strv_internal(strv, suffix, root, flags, dirs);
+ return conf_files_list_strv_internal(strv, suffix, root, flags, d);
}
int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dir, ...);
int conf_files_list_strv(char ***ret, const char *suffix, const char *root, unsigned flags, const char* const* dirs);
int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dirs);
-int conf_files_insert(char ***strv, const char *root, const char *dirs, const char *path);
+int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path);
+int conf_files_insert_nulstr(char ***strv, const char *root, const char *dirs, const char *path);