diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/path.c | 23 | ||||
-rw-r--r-- | options/path.h | 6 |
2 files changed, 21 insertions, 8 deletions
diff --git a/options/path.c b/options/path.c index ea36363a90..2895b7224b 100644 --- a/options/path.c +++ b/options/path.c @@ -91,6 +91,18 @@ static const char *mp_get_platform_path(void *talloc_ctx, return NULL; } +char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global, + const char *filename) +{ + void *tmp = talloc_new(NULL); + char *res = (char *)mp_get_platform_path(tmp, global, config_dirs[0]); + if (res) + res = mp_path_join(talloc_ctx, res, filename); + talloc_free(tmp); + MP_VERBOSE(global, "config file: '%s' -> '%s'\n", filename, res ? res : "-"); + return res; +} + static char **mp_find_all_config_files_limited(void *talloc_ctx, struct mpv_global *global, int max_files, @@ -316,13 +328,8 @@ void mp_mkdirp(const char *dir) void mp_mk_config_dir(struct mpv_global *global, char *subdir) { - void *tmp = talloc_new(NULL); - const char *dir = mp_get_platform_path(tmp, global, "home"); - - if (dir) { - dir = talloc_asprintf(tmp, "%s/%s", dir, subdir); + char *dir = mp_find_user_config_file(NULL, global, subdir); + if (dir) mp_mkdirp(dir); - } - - talloc_free(tmp); + talloc_free(dir); } diff --git a/options/path.h b/options/path.h index 1facea81cf..763a8dda54 100644 --- a/options/path.h +++ b/options/path.h @@ -31,6 +31,12 @@ struct mpv_global; char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, const char *filename); +// Like mp_find_config_file(), but search only the local writable user config +// dir. Also, this returns a result even if the file does not exist. Calling +// it with filename="" is equivalent to retrieving the user config dir. +char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global, + const char *filename); + // Find all instances of the given config file. Paths are returned in order // from lowest to highest priority. filename can contain multiple names // separated with '|', with the first having highest priority. |