From 7f55a39646af1696444be2a04dc0d212db3f7013 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Jun 2014 19:20:41 +0200 Subject: config: handle --no-config case directly in mp_config_dirs() Requires less special-casing, and probably also avoids that starting mpv with --no-config creates a config dir (even if nothing is loaded). --- options/path.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/options/path.c b/options/path.c index 0c3a7ba335..69786d8a83 100644 --- a/options/path.c +++ b/options/path.c @@ -103,10 +103,15 @@ static void mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i // priority static char **mp_config_dirs(void *talloc_ctx, struct mpv_global *global) { + struct MPOpts *opts = global->opts; + char **ret = talloc_zero_array(talloc_ctx, char*, MAX_CONFIG_PATHS); - if (global->opts->force_configdir && global->opts->force_configdir[0]) { - ret[0] = talloc_strdup(ret, global->opts->force_configdir); + if (!opts->load_config) + return ret; + + if (opts->force_configdir && opts->force_configdir[0]) { + ret[0] = talloc_strdup(ret, opts->force_configdir); return ret; } @@ -134,23 +139,19 @@ static char **mp_config_dirs(void *talloc_ctx, struct mpv_global *global) char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, const char *filename) { - struct MPOpts *opts = global->opts; - char *res = NULL; - if (opts->load_config) { - char **dirs = mp_config_dirs(NULL, global); - for (int i = 0; dirs && dirs[i]; i++) { - char *file = talloc_asprintf(talloc_ctx, "%s/%s", dirs[i], filename); - - if (mp_path_exists(file)) { - res = file; - break; - } + char **dirs = mp_config_dirs(NULL, global); + for (int i = 0; dirs && dirs[i]; i++) { + char *file = talloc_asprintf(talloc_ctx, "%s/%s", dirs[i], filename); - talloc_free(file); + if (mp_path_exists(file)) { + res = file; + break; } - talloc_free(dirs); + + talloc_free(file); } + talloc_free(dirs); MP_VERBOSE(global, "config path: '%s' -> '%s'\n", filename, res ? res : "(NULL)"); @@ -160,23 +161,19 @@ char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, char **mp_find_all_config_files(void *talloc_ctx, struct mpv_global *global, const char *filename) { - struct MPOpts *opts = global->opts; - char **ret = talloc_zero_array(talloc_ctx, char*, MAX_CONFIG_PATHS + 1); int num_ret = 0; - if (opts->load_config) { - char **dirs = mp_config_dirs(NULL, global); - for (int i = 0; dirs && dirs[i]; i++) { - char *file = talloc_asprintf(ret, "%s/%s", dirs[i], filename); + char **dirs = mp_config_dirs(NULL, global); + for (int i = 0; dirs && dirs[i]; i++) { + char *file = talloc_asprintf(ret, "%s/%s", dirs[i], filename); - if (!mp_path_exists(file) || num_ret >= MAX_CONFIG_PATHS) - continue; + if (!mp_path_exists(file) || num_ret >= MAX_CONFIG_PATHS) + continue; - ret[num_ret++] = file; - } - talloc_free(dirs); + ret[num_ret++] = file; } + talloc_free(dirs); for (int n = 0; n < num_ret / 2; n++) MPSWAP(char*, ret[n], ret[num_ret - n - 1]); -- cgit v1.2.3