Introduce config_new_load() as a new helper
This commit is contained in:
parent
3834d5329f
commit
f5e3a0fd4f
@ -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 */
|
||||
|
18
src/config.c
18
src/config.c
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user