(core_info.c) Better error handling for config file functions

This commit is contained in:
twinaphex 2016-12-14 13:15:23 +01:00
parent 43d06591c4
commit f303dd9e70

View File

@ -103,16 +103,28 @@ static void core_info_list_resolve_all_firmware(
char path_key[64]; char path_key[64];
char desc_key[64]; char desc_key[64];
char opt_key[64]; char opt_key[64];
bool tmp_bool = false;
path_key[0] = desc_key[0] = opt_key[0] = '\0'; char *tmp = NULL;
path_key[0] = desc_key[0] = opt_key[0] = '\0';
snprintf(path_key, sizeof(path_key), "firmware%u_path", c); snprintf(path_key, sizeof(path_key), "firmware%u_path", c);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c); snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c); snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
config_get_string(config, path_key, &info->firmware[c].path); if (config_get_string(config, path_key, &tmp))
config_get_string(config, desc_key, &info->firmware[c].desc); {
config_get_bool(config, opt_key , &info->firmware[c].optional); info->firmware[c].path = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(config, desc_key, &tmp))
{
info->firmware[c].desc = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_bool(config, opt_key , &tmp_bool))
info->firmware[c].optional = tmp_bool;
} }
} }
} }
@ -230,6 +242,7 @@ static core_info_list_t *core_info_list_new(const char *path)
contents, i) contents, i)
&& path_is_valid(info_path)) && path_is_valid(info_path))
{ {
char *tmp = NULL;
bool tmp_bool = false; bool tmp_bool = false;
unsigned count = 0; unsigned count = 0;
config_file_t *conf = config_file_new(info_path); config_file_t *conf = config_file_new(info_path);
@ -237,57 +250,106 @@ static core_info_list_t *core_info_list_new(const char *path)
if (!conf) if (!conf)
continue; continue;
config_get_string(conf, "display_name", if (config_get_string(conf, "display_name", &tmp))
&core_info[i].display_name); {
config_get_string(conf, "corename", core_info[i].display_name = strdup(tmp);
&core_info[i].core_name); free(tmp);
config_get_string(conf, "systemname", tmp = NULL;
&core_info[i].systemname); }
config_get_string(conf, "manufacturer", if (config_get_string(conf, "corename", &tmp))
&core_info[i].system_manufacturer); {
core_info[i].core_name = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "systemname", &tmp))
{
core_info[i].systemname = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "manufacturer", &tmp))
{
core_info[i].system_manufacturer = strdup(tmp);
free(tmp);
tmp = NULL;
}
config_get_uint(conf, "firmware_count", &count); config_get_uint(conf, "firmware_count", &count);
core_info[i].firmware_count = count; core_info[i].firmware_count = count;
if (config_get_string(conf, "supported_extensions",
&core_info[i].supported_extensions) && if (config_get_string(conf, "supported_extensions", &tmp))
core_info[i].supported_extensions) {
core_info[i].supported_extensions = strdup(tmp);
core_info[i].supported_extensions_list = core_info[i].supported_extensions_list =
string_split(core_info[i].supported_extensions, "|"); string_split(core_info[i].supported_extensions, "|");
if (config_get_string(conf, "authors", free(tmp);
&core_info[i].authors) && tmp = NULL;
core_info[i].authors) }
if (config_get_string(conf, "authors", &tmp))
{
core_info[i].authors = strdup(tmp);
core_info[i].authors_list = core_info[i].authors_list =
string_split(core_info[i].authors, "|"); string_split(core_info[i].authors, "|");
if (config_get_string(conf, "permissions", free(tmp);
&core_info[i].permissions) && tmp = NULL;
core_info[i].permissions) }
if (config_get_string(conf, "permissions", &tmp))
{
core_info[i].permissions = strdup(tmp);
core_info[i].permissions_list = core_info[i].permissions_list =
string_split(core_info[i].permissions, "|"); string_split(core_info[i].permissions, "|");
if (config_get_string(conf, "license", free(tmp);
&core_info[i].licenses) && tmp = NULL;
core_info[i].licenses) }
if (config_get_string(conf, "license", &tmp))
{
core_info[i].licenses = strdup(tmp);
core_info[i].licenses_list = core_info[i].licenses_list =
string_split(core_info[i].licenses, "|"); string_split(core_info[i].licenses, "|");
if (config_get_string(conf, "categories", free(tmp);
&core_info[i].categories) && tmp = NULL;
core_info[i].categories) }
if (config_get_string(conf, "categories", &tmp))
{
core_info[i].categories = strdup(tmp);
core_info[i].categories_list = core_info[i].categories_list =
string_split(core_info[i].categories, "|"); string_split(core_info[i].categories, "|");
if (config_get_string(conf, "database", free(tmp);
&core_info[i].databases) && tmp = NULL;
core_info[i].databases) }
if (config_get_string(conf, "database", &tmp))
{
core_info[i].databases = strdup(tmp);
core_info[i].databases_list = core_info[i].databases_list =
string_split(core_info[i].databases, "|"); string_split(core_info[i].databases, "|");
if (config_get_string(conf, "notes", free(tmp);
&core_info[i].notes) && tmp = NULL;
core_info[i].notes) }
if (config_get_string(conf, "notes", &tmp))
{
core_info[i].notes = strdup(tmp);
core_info[i].note_list = string_split(core_info[i].notes, "|"); core_info[i].note_list = string_split(core_info[i].notes, "|");
free(tmp);
tmp = NULL;
}
if (config_get_bool(conf, "supports_no_game", if (config_get_bool(conf, "supports_no_game",
&tmp_bool)) &tmp_bool))
core_info[i].supports_no_game = tmp_bool; core_info[i].supports_no_game = tmp_bool;
@ -823,7 +885,7 @@ bool core_info_list_get_display_name(core_info_list_t *core_info_list,
bool core_info_get_display_name(const char *path, char *s, size_t len) bool core_info_get_display_name(const char *path, char *s, size_t len)
{ {
bool ret = true; bool ret = true;
char *display_name = NULL; char *tmp = NULL;
config_file_t *conf = config_file_new(path); config_file_t *conf = config_file_new(path);
if (!conf) if (!conf)
@ -832,15 +894,14 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
goto error; goto error;
} }
config_get_string(conf, "display_name", &display_name); if (config_get_string(conf, "display_name", &tmp))
{
if (display_name) snprintf(s, len, "%s", tmp);
snprintf(s, len, "%s", display_name); free(tmp);
}
error: error:
config_file_free(conf); config_file_free(conf);
if (display_name)
free(display_name);
return ret; return ret;
} }