Create config_file_new_null

This commit is contained in:
twinaphex 2019-07-17 18:27:37 +02:00
parent 9eb61f0370
commit 0c31437c24
10 changed files with 34 additions and 25 deletions

View File

@ -2424,7 +2424,7 @@ static config_file_t *open_default_config_file(void)
bool saved = false;
/* Try to create a new config file. */
conf = config_file_new(NULL);
conf = config_file_new_null();
if (conf)
{
@ -2463,7 +2463,7 @@ static config_file_t *open_default_config_file(void)
if (!conf)
{
bool saved = false;
conf = config_file_new(NULL);
conf = config_file_new_null();
if (conf)
{
@ -2535,7 +2535,7 @@ static config_file_t *open_default_config_file(void)
if (conf)
RARCH_WARN("Config: using skeleton config \"%s\" as base for a new config file.\n", skeleton_conf);
else
conf = config_file_new(NULL);
conf = config_file_new_null();
free(skeleton_conf);
@ -3639,7 +3639,7 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
if (!conf)
{
conf = config_file_new(NULL);
conf = config_file_new_null();
if (!conf)
{
free(autoconf_file);
@ -3710,7 +3710,7 @@ bool config_save_file(const char *path)
int path_settings_size = sizeof(settings->paths) / sizeof(settings->paths.placeholder);
if (!conf)
conf = config_file_new(NULL);
conf = config_file_new_null();
if (!conf || rarch_ctl(RARCH_CTL_IS_OVERRIDES_ACTIVE, NULL))
{
@ -3993,7 +3993,7 @@ bool config_save_overrides(int override_type)
path_size);
if (!conf)
conf = config_file_new(NULL);
conf = config_file_new_null();
/* Load the original config file in memory */
config_load_file(path_get(RARCH_PATH_CONFIG), settings);

View File

@ -156,7 +156,7 @@ static void salamander_init(char *s, size_t len)
if (!config_exists)
{
config_file_t *conf = (config_file_t*)config_file_new(NULL);
config_file_t *conf = (config_file_t*)config_file_new_null();
if (conf)
{

View File

@ -170,8 +170,7 @@ bool input_remapping_save_file(const char *path)
if (!conf)
{
conf = config_file_new(NULL);
if (!conf)
if (!(conf = config_file_new_null()))
{
free(remap_file);
return false;

View File

@ -614,6 +614,23 @@ config_file_t *config_file_new(const char *path)
return config_file_new_internal(path, 0, NULL);
}
config_file_t *config_file_new_null(void)
{
struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
if (!conf)
return NULL;
conf->path = NULL;
conf->entries = NULL;
conf->tail = NULL;
conf->last = NULL;
conf->includes = NULL;
conf->include_depth = 0;
conf->guaranteed_no_duplicates = false ;
return conf;
}
static struct config_entry_list *config_get_entry(
const config_file_t *conf,
const char *key, struct config_entry_list **prev)

View File

@ -86,6 +86,8 @@ typedef struct config_file_cb config_file_cb_t ;
* NULL path will create an empty config file. */
config_file_t *config_file_new(const char *path);
config_file_t *config_file_new_null(void);
/* Loads a config file. Returns NULL if file doesn't exist.
* NULL path will create an empty config file.
* Includes cb callbacks to run custom code during config file processing.*/

View File

@ -168,10 +168,8 @@ bool cheat_manager_save(const char *path, const char *cheat_database, bool overw
conf = config_file_new(cheats_file);
if (!conf)
conf = config_file_new(NULL);
if (!conf)
return false;
if (!(conf = config_file_new_null()))
return false;
conf->guaranteed_no_duplicates = true;

View File

@ -4037,11 +4037,8 @@ static int action_ok_option_create(const char *path,
conf = config_file_new(game_path);
if (!conf)
{
conf = config_file_new(NULL);
if (!conf)
if (!(conf = config_file_new_null()))
return false;
}
if (config_file_write(conf, game_path, true))
{

View File

@ -357,9 +357,7 @@ bool menu_shader_manager_save_preset(
dirs[2] = config_directory;
}
conf = (config_file_t*)config_file_new(NULL);
if (!conf)
if (!(conf = (config_file_t*)config_file_new_null()))
return false;
if (fullpath)

View File

@ -2086,7 +2086,7 @@ static core_option_manager_t *core_option_manager_new_vars(const char *conf_path
}
if (!opt->conf)
opt->conf = config_file_new(NULL);
opt->conf = config_file_new_null();
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));
@ -2154,7 +2154,7 @@ static core_option_manager_t *core_option_manager_new(const char *conf_path,
}
if (!opt->conf)
opt->conf = config_file_new(NULL);
opt->conf = config_file_new_null();
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));

View File

@ -137,9 +137,7 @@ void CoreOptionsDialog::onSaveGameSpecificOptions()
if (!conf)
{
conf = config_file_new(NULL);
if (!conf)
if (!(conf = config_file_new_null()))
{
QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE));
return;