(config_file) Cleanups

This commit is contained in:
twinaphex 2020-08-24 21:11:41 +02:00
parent 150e96144a
commit 4f29bef56e
2 changed files with 19 additions and 5 deletions

View File

@ -574,14 +574,11 @@ error:
return NULL; return NULL;
} }
void config_file_free(config_file_t *conf) static void config_file_deinitialize_internal(config_file_t *conf)
{ {
struct config_include_list *inc_tmp = NULL; struct config_include_list *inc_tmp = NULL;
struct config_entry_list *tmp = NULL; struct config_entry_list *tmp = conf->entries;
if (!conf)
return;
tmp = conf->entries;
while (tmp) while (tmp)
{ {
struct config_entry_list *hold = NULL; struct config_entry_list *hold = NULL;
@ -614,9 +611,24 @@ void config_file_free(config_file_t *conf)
if (conf->path) if (conf->path)
free(conf->path); free(conf->path);
}
void config_file_free(config_file_t *conf)
{
if (!conf)
return;
config_file_deinitialize_internal(conf);
free(conf); free(conf);
} }
bool config_file_deinitialize(config_file_t *conf)
{
if (!conf)
return false;
config_file_deinitialize_internal(conf);
return true;
}
bool config_append_file(config_file_t *conf, const char *path) bool config_append_file(config_file_t *conf, const char *path)
{ {
config_file_t *new_conf = config_file_new_from_path_to_string(path); config_file_t *new_conf = config_file_new_from_path_to_string(path);

View File

@ -105,6 +105,8 @@ config_file_t *config_file_new_from_path_to_string(const char *path);
/* Frees config file. */ /* Frees config file. */
void config_file_free(config_file_t *conf); void config_file_free(config_file_t *conf);
bool config_file_deinitialize(config_file_t *conf);
/* Loads a new config, and appends its data to conf. /* Loads a new config, and appends its data to conf.
* The key-value pairs of the new config file takes priority over the old. */ * The key-value pairs of the new config file takes priority over the old. */
bool config_append_file(config_file_t *conf, const char *path); bool config_append_file(config_file_t *conf, const char *path);