mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 00:40:09 +00:00
(core_info.c) Reduce stack size usage
This commit is contained in:
parent
3860d95c8f
commit
a2317bf1e1
91
core_info.c
91
core_info.c
@ -189,19 +189,21 @@ static bool core_info_list_iterate(
|
|||||||
char *s, size_t len,
|
char *s, size_t len,
|
||||||
struct string_list *contents, size_t i)
|
struct string_list *contents, size_t i)
|
||||||
{
|
{
|
||||||
char info_path_base[PATH_MAX_LENGTH];
|
size_t info_path_base_size = PATH_MAX_LENGTH * sizeof(char);
|
||||||
|
char *info_path_base = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA))
|
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA))
|
||||||
char *substr = NULL;
|
char *substr = NULL;
|
||||||
#endif
|
#endif
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
if (!contents || !contents->elems[i].data)
|
if (!contents || !contents->elems[i].data)
|
||||||
return false;
|
goto error;
|
||||||
|
|
||||||
info_path_base[0] = '\0';
|
info_path_base[0] = '\0';
|
||||||
|
|
||||||
fill_pathname_base_noext(info_path_base, contents->elems[i].data,
|
fill_pathname_base_noext(info_path_base,
|
||||||
sizeof(info_path_base));
|
contents->elems[i].data,
|
||||||
|
info_path_base_size);
|
||||||
|
|
||||||
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP))
|
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP))
|
||||||
substr = strrchr(info_path_base, '_');
|
substr = strrchr(info_path_base, '_');
|
||||||
@ -211,14 +213,20 @@ static bool core_info_list_iterate(
|
|||||||
|
|
||||||
strlcat(info_path_base,
|
strlcat(info_path_base,
|
||||||
file_path_str(FILE_PATH_CORE_INFO_EXTENSION),
|
file_path_str(FILE_PATH_CORE_INFO_EXTENSION),
|
||||||
sizeof(info_path_base));
|
info_path_base_size);
|
||||||
|
|
||||||
fill_pathname_join(s,
|
fill_pathname_join(s,
|
||||||
(!string_is_empty(settings->paths.path_libretro_info)) ?
|
(!string_is_empty(settings->paths.path_libretro_info)) ?
|
||||||
settings->paths.path_libretro_info : settings->paths.directory_libretro,
|
settings->paths.path_libretro_info :
|
||||||
|
settings->paths.directory_libretro,
|
||||||
info_path_base, len);
|
info_path_base, len);
|
||||||
|
|
||||||
|
free(info_path_base);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(info_path_base);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static core_info_list_t *core_info_list_new(const char *path)
|
static core_info_list_t *core_info_list_new(const char *path)
|
||||||
@ -245,12 +253,13 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
|
|
||||||
for (i = 0; i < contents->size; i++)
|
for (i = 0; i < contents->size; i++)
|
||||||
{
|
{
|
||||||
char info_path[PATH_MAX_LENGTH];
|
size_t info_path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||||
|
char *info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
|
||||||
info_path[0] = '\0';
|
info_path[0] = '\0';
|
||||||
|
|
||||||
if (
|
if (
|
||||||
core_info_list_iterate(info_path, sizeof(info_path),
|
core_info_list_iterate(info_path, info_path_size,
|
||||||
contents, i)
|
contents, i)
|
||||||
&& path_is_valid(info_path))
|
&& path_is_valid(info_path))
|
||||||
{
|
{
|
||||||
@ -259,30 +268,36 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
config_file_t *conf = config_file_new(info_path);
|
config_file_t *conf = config_file_new(info_path);
|
||||||
|
|
||||||
|
free(info_path);
|
||||||
|
|
||||||
if (!conf)
|
if (!conf)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (config_get_string(conf, "display_name", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "display_name", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].display_name = strdup(tmp);
|
core_info[i].display_name = strdup(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
if (config_get_string(conf, "corename", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "corename", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].core_name = strdup(tmp);
|
core_info[i].core_name = strdup(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "systemname", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "systemname", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].systemname = strdup(tmp);
|
core_info[i].systemname = strdup(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "manufacturer", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "manufacturer", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].system_manufacturer = strdup(tmp);
|
core_info[i].system_manufacturer = strdup(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
@ -293,7 +308,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
|
|
||||||
core_info[i].firmware_count = count;
|
core_info[i].firmware_count = count;
|
||||||
|
|
||||||
if (config_get_string(conf, "supported_extensions", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "supported_extensions", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].supported_extensions = strdup(tmp);
|
core_info[i].supported_extensions = strdup(tmp);
|
||||||
core_info[i].supported_extensions_list =
|
core_info[i].supported_extensions_list =
|
||||||
@ -303,7 +319,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "authors", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "authors", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].authors = strdup(tmp);
|
core_info[i].authors = strdup(tmp);
|
||||||
core_info[i].authors_list =
|
core_info[i].authors_list =
|
||||||
@ -313,7 +330,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "permissions", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "permissions", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].permissions = strdup(tmp);
|
core_info[i].permissions = strdup(tmp);
|
||||||
core_info[i].permissions_list =
|
core_info[i].permissions_list =
|
||||||
@ -323,7 +341,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "license", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "license", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].licenses = strdup(tmp);
|
core_info[i].licenses = strdup(tmp);
|
||||||
core_info[i].licenses_list =
|
core_info[i].licenses_list =
|
||||||
@ -333,7 +352,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "categories", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "categories", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].categories = strdup(tmp);
|
core_info[i].categories = strdup(tmp);
|
||||||
core_info[i].categories_list =
|
core_info[i].categories_list =
|
||||||
@ -343,7 +363,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "database", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "database", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].databases = strdup(tmp);
|
core_info[i].databases = strdup(tmp);
|
||||||
core_info[i].databases_list =
|
core_info[i].databases_list =
|
||||||
@ -353,7 +374,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "notes", &tmp) && !string_is_empty(tmp))
|
if (config_get_string(conf, "notes", &tmp)
|
||||||
|
&& !string_is_empty(tmp))
|
||||||
{
|
{
|
||||||
core_info[i].notes = strdup(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, "|");
|
||||||
@ -372,6 +394,8 @@ static core_info_list_t *core_info_list_new(const char *path)
|
|||||||
|
|
||||||
core_info[i].config_data = conf;
|
core_info[i].config_data = conf;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
free(info_path);
|
||||||
|
|
||||||
if (!string_is_empty(contents->elems[i].data))
|
if (!string_is_empty(contents->elems[i].data))
|
||||||
core_info[i].path = strdup(contents->elems[i].data);
|
core_info[i].path = strdup(contents->elems[i].data);
|
||||||
@ -493,17 +517,18 @@ static bool core_info_list_update_missing_firmware_internal(
|
|||||||
const char *systemdir)
|
const char *systemdir)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char path[PATH_MAX_LENGTH];
|
|
||||||
core_info_t *info = NULL;
|
core_info_t *info = NULL;
|
||||||
|
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||||
|
char *path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
|
||||||
if (!core_info_list || !core)
|
if (!core_info_list || !core)
|
||||||
return false;
|
goto error;
|
||||||
|
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
info = core_info_find_internal(core_info_list, core);
|
info = core_info_find_internal(core_info_list, core);
|
||||||
|
|
||||||
if (!info)
|
if (!info)
|
||||||
return false;
|
goto error;
|
||||||
|
|
||||||
rarch_ctl(RARCH_CTL_UNSET_MISSING_BIOS, NULL);
|
rarch_ctl(RARCH_CTL_UNSET_MISSING_BIOS, NULL);
|
||||||
for (i = 0; i < info->firmware_count; i++)
|
for (i = 0; i < info->firmware_count; i++)
|
||||||
@ -512,7 +537,7 @@ static bool core_info_list_update_missing_firmware_internal(
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
fill_pathname_join(path, systemdir,
|
fill_pathname_join(path, systemdir,
|
||||||
info->firmware[i].path, sizeof(path));
|
info->firmware[i].path, path_size);
|
||||||
info->firmware[i].missing = !path_file_exists(path);
|
info->firmware[i].missing = !path_file_exists(path);
|
||||||
if (info->firmware[i].missing && !info->firmware[i].optional)
|
if (info->firmware[i].missing && !info->firmware[i].optional)
|
||||||
{
|
{
|
||||||
@ -521,7 +546,12 @@ static bool core_info_list_update_missing_firmware_internal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(path);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
free(path);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -732,24 +762,34 @@ void core_info_get_name(const char *path, char *s, size_t len)
|
|||||||
|
|
||||||
for (i = 0; i < contents->size; i++)
|
for (i = 0; i < contents->size; i++)
|
||||||
{
|
{
|
||||||
char info_path[PATH_MAX_LENGTH];
|
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||||
|
char *info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
config_file_t *conf = NULL;
|
config_file_t *conf = NULL;
|
||||||
char *new_core_name = NULL;
|
char *new_core_name = NULL;
|
||||||
|
|
||||||
info_path[0] = '\0';
|
info_path[0] = '\0';
|
||||||
|
|
||||||
if (!string_is_equal(contents->elems[i].data, path))
|
if (!string_is_equal(contents->elems[i].data, path))
|
||||||
|
{
|
||||||
|
free(info_path);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!core_info_list_iterate(info_path,
|
if (!core_info_list_iterate(info_path,
|
||||||
sizeof(info_path), contents, i)
|
path_size, contents, i)
|
||||||
&& path_is_valid(info_path))
|
&& path_is_valid(info_path))
|
||||||
|
{
|
||||||
|
free(info_path);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
conf = config_file_new(info_path);
|
conf = config_file_new(info_path);
|
||||||
|
|
||||||
if (!conf)
|
if (!conf)
|
||||||
|
{
|
||||||
|
free(info_path);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (config_get_string(conf, "corename",
|
if (config_get_string(conf, "corename",
|
||||||
&new_core_name))
|
&new_core_name))
|
||||||
@ -759,6 +799,7 @@ void core_info_get_name(const char *path, char *s, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
config_file_free(conf);
|
config_file_free(conf);
|
||||||
|
free(info_path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user