Reduce char arrays

This commit is contained in:
LibretroAdmin 2025-01-17 12:55:45 +01:00
parent 16209a0936
commit 1e83bfb971

View File

@ -28,55 +28,46 @@
int config_userdata_get_float(void *userdata, const char *key_str, int config_userdata_get_float(void *userdata, const char *key_str,
float *value, float default_value) float *value, float default_value)
{ {
bool got; char key[256];
char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata; struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key));
fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); if (config_get_float(usr->conf, key, value))
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); return true;
*value = default_value;
got = config_get_float (usr->conf, key[0], value); fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key));
got = got || config_get_float(usr->conf, key[1], value); if (config_get_float(usr->conf, key, value))
return true;
if (!got) return false;
*value = default_value;
return got;
} }
int config_userdata_get_int(void *userdata, const char *key_str, int config_userdata_get_int(void *userdata, const char *key_str,
int *value, int default_value) int *value, int default_value)
{ {
bool got; char key[256];
char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata; struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key));
fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); if (config_get_int(usr->conf, key, value))
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); return true;
*value = default_value;
got = config_get_int (usr->conf, key[0], value); fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key));
got = got || config_get_int(usr->conf, key[1], value); if (config_get_int(usr->conf, key, value))
return true;
if (!got) return false;
*value = default_value;
return got;
} }
int config_userdata_get_hex(void *userdata, const char *key_str, int config_userdata_get_hex(void *userdata, const char *key_str,
unsigned *value, unsigned default_value) unsigned *value, unsigned default_value)
{ {
bool got; char key[256];
char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata; struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
fill_pathname_join_delim(key, usr->prefix[0], key_str, '_', sizeof(key));
fill_pathname_join_delim(key[0], usr->prefix[0], key_str, '_', sizeof(key[0])); if (config_get_hex(usr->conf, key, value))
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); return true;
*value = default_value;
got = config_get_hex(usr->conf, key[0], value); fill_pathname_join_delim(key, usr->prefix[1], key_str, '_', sizeof(key));
got = got || config_get_hex(usr->conf, key[1], value); if (config_get_hex(usr->conf, key, value))
return true;
if (!got) return false;
*value = default_value;
return got;
} }
int config_userdata_get_float_array(void *userdata, const char *key_str, 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) const float *default_values, unsigned num_default_values)
{ {
char key[2][256]; char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
char *str = NULL; 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[0], usr->prefix[0], key_str, '_', sizeof(key[0]));
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1]));
if ( config_get_string(usr->conf, key[0], &str) || if ( config_get_string(usr->conf, key[0], &str)
config_get_string(usr->conf, key[1], &str)) || config_get_string(usr->conf, key[1], &str))
{ {
unsigned i; unsigned i;
struct string_list list = {0}; 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) const int *default_values, unsigned num_default_values)
{ {
char key[2][256]; char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
char *str = NULL; 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[0], usr->prefix[0], key_str, '_', sizeof(key[0]));
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1]));
if ( config_get_string(usr->conf, key[0], &str) || if ( config_get_string(usr->conf, key[0], &str)
config_get_string(usr->conf, key[1], &str)) || config_get_string(usr->conf, key[1], &str))
{ {
unsigned i; unsigned i;
struct string_list list = {0}; 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 **output, const char *default_output)
{ {
char key[2][256]; char key[2][256];
struct config_file_userdata *usr = (struct config_file_userdata*)userdata;
char *str = NULL; 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[0], usr->prefix[0], key_str, '_', sizeof(key[0]));
fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1])); fill_pathname_join_delim(key[1], usr->prefix[1], key_str, '_', sizeof(key[1]));
if ( config_get_string(usr->conf, key[0], &str) || if ( config_get_string(usr->conf, key[0], &str)
config_get_string(usr->conf, key[1], &str)) || config_get_string(usr->conf, key[1], &str))
{ {
*output = str; *output = str;
return true; return true;