From cb064052934d6f7e71cd5e5cd5cf04130b04a99c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 17 Jul 2019 20:20:39 +0200 Subject: [PATCH] open_default_config - small cleanups --- configuration.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/configuration.c b/configuration.c index 9d15b4dca4..8cc3afce25 100644 --- a/configuration.c +++ b/configuration.c @@ -2391,11 +2391,10 @@ static config_file_t *open_default_config_file(void) config_file_t *conf = NULL; (void)has_application_data; + (void)path_size; application_data[0] = conf_path[0] = app_path[0] = '\0'; - (void)path_size; - #if defined(_WIN32) && !defined(_XBOX) #if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP /* On UWP, the app install directory is not writable so use the writable LocalState dir instead */ @@ -2505,9 +2504,10 @@ static config_file_t *open_default_config_file(void) if (!conf && has_application_data) { - char *basedir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); + bool dir_created = false; + char *basedir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); - basedir[0] = '\0'; + basedir[0] = '\0'; /* Try to create a new config file. */ @@ -2518,16 +2518,18 @@ static config_file_t *open_default_config_file(void) fill_pathname_join(conf_path, conf_path, file_path_str(FILE_PATH_MAIN_CONFIG), path_size); - if (path_mkdir(basedir)) + dir_created = path_mkdir(basedir); + free(basedir); + + if (dir_created) { char *skeleton_conf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); bool saved = false; skeleton_conf[0] = '\0'; - free(basedir); - - /* Build a retroarch.cfg path from the global config directory (/etc). */ + /* Build a retroarch.cfg path from the + * global config directory (/etc). */ fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR, file_path_str(FILE_PATH_MAIN_CONFIG), path_size); @@ -2541,7 +2543,8 @@ static config_file_t *open_default_config_file(void) if (conf) { - /* Since this is a clean config file, we can safely use config_save_on_exit. */ + /* Since this is a clean config file, we can + * safely use config_save_on_exit. */ config_set_bool(conf, "config_save_on_exit", true); saved = config_file_write(conf, conf_path, true); } @@ -2555,10 +2558,6 @@ static config_file_t *open_default_config_file(void) RARCH_WARN("Config: Created new config file in: \"%s\".\n", conf_path); } - else - { - free(basedir); - } } #endif