path-lookup: Add config_directory_generic()

This commit is contained in:
Daan De Meyer
2026-01-21 12:03:08 +01:00
parent 688ebd3313
commit 4b070c4c9f
2 changed files with 26 additions and 9 deletions
+25 -9
View File
@@ -33,9 +33,30 @@ int user_search_dirs(const char *suffix, char ***ret_config_dirs, char ***ret_da
return 0;
}
int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret) {
int r;
int config_directory_generic(RuntimeScope scope, const char *suffix, char **ret) {
assert(ret);
/* This does not bother with $CONFIGURATION_DIRECTORY, and hence can be applied to get other
* service's config dir */
switch (scope) {
case RUNTIME_SCOPE_USER:
return xdg_user_config_dir(suffix, ret);
case RUNTIME_SCOPE_SYSTEM: {
char *d = path_join("/etc", suffix);
if (!d)
return -ENOMEM;
*ret = d;
return 0;
}
default:
return -EINVAL;
}
}
int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret) {
assert(ret);
/* This does not bother with $RUNTIME_DIRECTORY, and hence can be applied to get other service's
@@ -43,24 +64,19 @@ int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret
switch (scope) {
case RUNTIME_SCOPE_USER:
r = xdg_user_runtime_dir(suffix, ret);
if (r < 0)
return r;
break;
return xdg_user_runtime_dir(suffix, ret);
case RUNTIME_SCOPE_SYSTEM: {
char *d = path_join("/run", suffix);
if (!d)
return -ENOMEM;
*ret = d;
break;
return 0;
}
default:
return -EINVAL;
}
return 0;
}
int runtime_directory(RuntimeScope scope, const char *fallback_suffix, char **ret) {
+1
View File
@@ -57,6 +57,7 @@ int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFl
void lookup_paths_log(LookupPaths *p);
void lookup_paths_done(LookupPaths *p);
int config_directory_generic(RuntimeScope scope, const char *suffix, char **ret);
int runtime_directory_generic(RuntimeScope scope, const char *suffix, char **ret);
int runtime_directory(RuntimeScope scope, const char *fallback_suffix, char **ret);