summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-01 22:47:30 +0200
committerwm4 <wm4@nowhere>2013-05-05 19:35:04 +0200
commit497ec230bfa3cec58bdb009d05ef4664aadbdd75 (patch)
tree96d3f7c2040b90e22c0ba92e557f8bfb0128cb72 /core
parent5165e19a238cce0f7170ae80707ede814a630d66 (diff)
downloadmpv-497ec230bfa3cec58bdb009d05ef4664aadbdd75.tar.bz2
mpv-497ec230bfa3cec58bdb009d05ef4664aadbdd75.tar.xz
mplayer: factor config dir creation
Move it into its own function.
Diffstat (limited to 'core')
-rw-r--r--core/mplayer.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/core/mplayer.c b/core/mplayer.c
index 5d8976c491..9028cbafce 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -608,6 +608,16 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx,
exit(rc);
}
+static void mk_config_dir(char *subdir)
+{
+ void *tmp = talloc_new(NULL);
+ char *confdir = talloc_steal(tmp, mp_find_user_config_file(""));
+ if (subdir)
+ confdir = mp_path_join(tmp, bstr0(confdir), bstr0(subdir));
+ mkdir(confdir, 0777);
+ talloc_free(tmp);
+}
+
#include "cfg-mplayer.h"
static int cfg_include(struct m_config *conf, char *filename)
@@ -626,26 +636,21 @@ static bool parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
return true;
if (!m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mpv.conf") < 0)
return false;
- if ((conffile = mp_find_user_config_file("")) == NULL)
- mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n");
+ mk_config_dir(NULL);
+ if ((conffile = mp_find_user_config_file("config")) == NULL)
+ mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
+ "mp_find_user_config_file(\"config\") problem\n");
else {
- mkdir(conffile, 0777);
- talloc_free(conffile);
- if ((conffile = mp_find_user_config_file("config")) == NULL)
- mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
- "mp_find_user_config_file(\"config\") problem\n");
- else {
- if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY,
- 0666)) != -1) {
- mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
- "Creating config file: %s\n", conffile);
- write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1);
- close(conffile_fd);
- }
- if (m_config_parse_config_file(conf, conffile) < 0)
- return false;
- talloc_free(conffile);
+ if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY,
+ 0666)) != -1) {
+ mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
+ "Creating config file: %s\n", conffile);
+ write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1);
+ close(conffile_fd);
}
+ if (m_config_parse_config_file(conf, conffile) < 0)
+ return false;
+ talloc_free(conffile);
}
return true;
}