summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-21 15:49:19 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commit3569857b7580f9037f5168a2e3888a86cc3a85a0 (patch)
tree271d3a35b844ec1ffa6e2c5a7069ae25f962e831 /options
parentfe6b2f9103450679a07da44bdad31707b597cd20 (diff)
downloadmpv-3569857b7580f9037f5168a2e3888a86cc3a85a0.tar.bz2
mpv-3569857b7580f9037f5168a2e3888a86cc3a85a0.tar.xz
path: don't access global option struct
The path functions need to access the option that forces non-default config directories. Just add it as a field to mpv_global - it seems justified. The accessed options were always enforced as immutable after init, so there's not much of a change.
Diffstat (limited to 'options')
-rw-r--r--options/path.c22
-rw-r--r--options/path.h3
2 files changed, 18 insertions, 7 deletions
diff --git a/options/path.c b/options/path.c
index dac9238cf9..d2b74516e1 100644
--- a/options/path.c
+++ b/options/path.c
@@ -61,6 +61,19 @@ static const char *const config_dirs[] = {
"global",
};
+void mp_init_paths(struct mpv_global *global, struct MPOpts *opts)
+{
+ TA_FREEP(&global->configdir);
+
+ const char *force_configdir = getenv("MPV_HOME");
+ if (opts->force_configdir && opts->force_configdir[0])
+ force_configdir = opts->force_configdir;
+ if (!opts->load_config)
+ force_configdir = "";
+
+ global->configdir = talloc_strdup(global, force_configdir);
+}
+
// Return a platform specific path using a path type as defined in osdep/path.h.
// Keep in mind that the only way to free the return value is freeing talloc_ctx
// (or its children), as this function can return a statically allocated string.
@@ -70,15 +83,10 @@ static const char *mp_get_platform_path(void *talloc_ctx,
{
assert(talloc_ctx);
- const char *force_configdir = getenv("MPV_HOME");
- if (global->opts->force_configdir && global->opts->force_configdir[0])
- force_configdir = global->opts->force_configdir;
- if (!global->opts->load_config)
- force_configdir = "";
- if (force_configdir) {
+ if (global->configdir) {
for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) {
if (strcmp(config_dirs[n], type) == 0)
- return (n == 0 && force_configdir[0]) ? force_configdir : NULL;
+ return (n == 0 && global->configdir[0]) ? global->configdir : NULL;
}
}
diff --git a/options/path.h b/options/path.h
index 0d488fcb89..c3c3699a0b 100644
--- a/options/path.h
+++ b/options/path.h
@@ -24,6 +24,9 @@
#include "misc/bstr.h"
struct mpv_global;
+struct MPOpts;
+
+void mp_init_paths(struct mpv_global *global, struct MPOpts *opts);
// Search for the input filename in several paths. These include user and global
// config locations by default. Some platforms may implement additional platform