From 497ec230bfa3cec58bdb009d05ef4664aadbdd75 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 1 Apr 2013 22:47:30 +0200 Subject: mplayer: factor config dir creation Move it into its own function. --- core/mplayer.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'core') 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; } -- cgit v1.2.3