From 1e83bfb97159e522e6689aa70d2435ca5ddeffe2 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Fri, 17 Jan 2025 12:55:45 +0100 Subject: [PATCH] Reduce char arrays --- libretro-common/file/config_file_userdata.c | 81 +++++++++------------ 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/libretro-common/file/config_file_userdata.c b/libretro-common/file/config_file_userdata.c index 799ce5f2a4ff..e0459f3df747 100644 --- a/libretro-common/file/config_file_userdata.c +++ b/libretro-common/file/config_file_userdata.c @@ -28,55 +28,46 @@ int config_userdata_get_float(void *userdata, const char *key_str, float *value, float default_value) { - bool got; - char key[2][256]; + char key[256]; struct config_file_userdata *usr = (struct config_file_userdata*)userdata; - - fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); - fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - - got = config_get_float (usr->conf, key[0], value); - got = got || config_get_float(usr->conf, key[1], value); - - if (!got) - *value = default_value; - return got; + fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key)); + if (config_get_float(usr->conf, key, value)) + return true; + *value = default_value; + fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key)); + if (config_get_float(usr->conf, key, value)) + return true; + return false; } int config_userdata_get_int(void *userdata, const char *key_str, int *value, int default_value) { - bool got; - char key[2][256]; + char key[256]; struct config_file_userdata *usr = (struct config_file_userdata*)userdata; - - fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); - fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - - got = config_get_int (usr->conf, key[0], value); - got = got || config_get_int(usr->conf, key[1], value); - - if (!got) - *value = default_value; - return got; + fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key)); + if (config_get_int(usr->conf, key, value)) + return true; + *value = default_value; + fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key)); + if (config_get_int(usr->conf, key, value)) + return true; + return false; } int config_userdata_get_hex(void *userdata, const char *key_str, unsigned *value, unsigned default_value) { - bool got; - char key[2][256]; + char key[256]; struct config_file_userdata *usr = (struct config_file_userdata*)userdata; - - fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); - fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - - got = config_get_hex(usr->conf, key[0], value); - got = got || config_get_hex(usr->conf, key[1], value); - - if (!got) - *value = default_value; - return got; + fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key)); + if (config_get_hex(usr->conf, key, value)) + return true; + *value = default_value; + fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key)); + if (config_get_hex(usr->conf, key, value)) + return true; + return false; } int config_userdata_get_float_array(void *userdata, const char *key_str, @@ -84,14 +75,14 @@ int config_userdata_get_float_array(void *userdata, const char *key_str, const float *default_values, unsigned num_default_values) { char key[2][256]; - struct config_file_userdata *usr = (struct config_file_userdata*)userdata; char *str = NULL; + struct config_file_userdata *usr = (struct config_file_userdata*)userdata; fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - if ( config_get_string(usr->conf, key[0], &str) || - config_get_string(usr->conf, key[1], &str)) + if ( config_get_string(usr->conf, key[0], &str) + || config_get_string(usr->conf, key[1], &str)) { unsigned i; struct string_list list = {0}; @@ -117,13 +108,13 @@ int config_userdata_get_int_array(void *userdata, const char *key_str, const int *default_values, unsigned num_default_values) { char key[2][256]; - struct config_file_userdata *usr = (struct config_file_userdata*)userdata; char *str = NULL; + struct config_file_userdata *usr = (struct config_file_userdata*)userdata; fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - if ( config_get_string(usr->conf, key[0], &str) || - config_get_string(usr->conf, key[1], &str)) + if ( config_get_string(usr->conf, key[0], &str) + || config_get_string(usr->conf, key[1], &str)) { unsigned i; struct string_list list = {0}; @@ -148,13 +139,13 @@ int config_userdata_get_string(void *userdata, const char *key_str, char **output, const char *default_output) { char key[2][256]; - struct config_file_userdata *usr = (struct config_file_userdata*)userdata; char *str = NULL; + struct config_file_userdata *usr = (struct config_file_userdata*)userdata; fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); - if ( config_get_string(usr->conf, key[0], &str) || - config_get_string(usr->conf, key[1], &str)) + if ( config_get_string(usr->conf, key[0], &str) + || config_get_string(usr->conf, key[1], &str)) { *output = str; return true;