Introduce config_new_load() as a new helper

This commit is contained in:
Pierre Pronchery 2020-09-30 05:42:23 +02:00
parent 3834d5329f
commit f5e3a0fd4f
2 changed files with 19 additions and 0 deletions

View File

@ -49,6 +49,7 @@ typedef void (*ConfigForeachSectionCallback)(String const * variable,
/* functions */
Config * config_new(void);
Config * config_new_load(String const * filename);
void config_delete(Config * config);
/* accessors */

View File

@ -81,6 +81,24 @@ Config * config_new(void)
}
/* config_new_load */
Config * config_new_load(String const * filename)
{
Config * config;
if(filename == NULL)
return config_new();
if((config = config_new()) == NULL)
return NULL;
if(config_load(config, filename) != 0)
{
config_delete(config);
return NULL;
}
return config;
}
/* config_delete */
void config_delete(Config * config)
{