summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-26 19:20:41 +0200
committerwm4 <wm4@nowhere>2014-06-26 19:56:45 +0200
commit7f55a39646af1696444be2a04dc0d212db3f7013 (patch)
tree786d6e0d687909565f7e90f1414f218d1f64543c /options
parentb4d64ac43432f99ff20357226c8b41a2e71583f7 (diff)
downloadmpv-7f55a39646af1696444be2a04dc0d212db3f7013.tar.bz2
mpv-7f55a39646af1696444be2a04dc0d212db3f7013.tar.xz
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).
Diffstat (limited to 'options')
-rw-r--r--options/path.c49
1 files 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]);