Skip to content

Commit

Permalink
Reduce char arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jan 17, 2025
1 parent 16209a0 commit 1e83bfb
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions libretro-common/file/config_file_userdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,61 @@
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,
float **values, unsigned *out_num_values,
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};
Expand All @@ -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};
Expand All @@ -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;
Expand Down

0 comments on commit 1e83bfb

Please sign in to comment.