mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
config_file.c - cleanups
This commit is contained in:
parent
f681cb455c
commit
b05b27bff6
@ -177,15 +177,15 @@ static char *extract_value(char *line, bool is_value)
|
||||
{
|
||||
line++;
|
||||
tok = strtok_r(line, "\"", &save);
|
||||
if (!tok)
|
||||
return NULL;
|
||||
return strdup(tok);
|
||||
goto end;
|
||||
}
|
||||
else if (*line == '\0') /* Nothing */
|
||||
return NULL;
|
||||
|
||||
/* We don't have that. Read until next space. */
|
||||
tok = strtok_r(line, " \n\t\f\r\v", &save);
|
||||
|
||||
end:
|
||||
if (tok)
|
||||
return strdup(tok);
|
||||
return NULL;
|
||||
@ -481,7 +481,7 @@ void config_file_free(config_file_t *conf)
|
||||
{
|
||||
struct config_include_list *hold = NULL;
|
||||
free(inc_tmp->path);
|
||||
hold = (struct config_include_list*)inc_tmp;
|
||||
hold = (struct config_include_list*)inc_tmp;
|
||||
inc_tmp = inc_tmp->next;
|
||||
free(hold);
|
||||
}
|
||||
@ -575,7 +575,6 @@ config_file_t *config_file_new(const char *path)
|
||||
return config_file_new_internal(path, 0);
|
||||
}
|
||||
|
||||
|
||||
static struct config_entry_list *config_get_entry(const config_file_t *conf,
|
||||
const char *key, struct config_entry_list **prev)
|
||||
{
|
||||
@ -606,9 +605,12 @@ bool config_get_double(config_file_t *conf, const char *key, double *in)
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
if (entry)
|
||||
{
|
||||
*in = strtod(entry->value, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
return entry != NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_float(config_file_t *conf, const char *key, float *in)
|
||||
@ -619,9 +621,9 @@ bool config_get_float(config_file_t *conf, const char *key, float *in)
|
||||
{
|
||||
/* strtof() is C99/POSIX. Just use the more portable kind. */
|
||||
*in = (float)strtod(entry->value, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
return entry != NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_int(config_file_t *conf, const char *key, int *in)
|
||||
@ -634,10 +636,13 @@ bool config_get_int(config_file_t *conf, const char *key, int *in)
|
||||
int val = (int)strtol(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
|
||||
@ -651,10 +656,12 @@ bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
|
||||
uint64_t val = strtoull(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -668,10 +675,13 @@ bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
|
||||
unsigned val = (unsigned)strtoul(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
|
||||
@ -684,10 +694,13 @@ bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
|
||||
unsigned val = (unsigned)strtoul(entry->value, NULL, 16);
|
||||
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_char(config_file_t *conf, const char *key, char *in)
|
||||
@ -700,9 +713,10 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
|
||||
return false;
|
||||
|
||||
*in = *entry->value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return entry != NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_string(config_file_t *conf, const char *key, char **str)
|
||||
@ -710,9 +724,11 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
if (entry)
|
||||
{
|
||||
*str = strdup(entry->value);
|
||||
|
||||
return entry != NULL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_config_path(config_file_t *conf, char *s, size_t len)
|
||||
@ -730,23 +746,25 @@ bool config_get_array(config_file_t *conf, const char *key,
|
||||
|
||||
if (entry)
|
||||
return strlcpy(buf, entry->value, size) < size;
|
||||
|
||||
return entry != NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_path(config_file_t *conf, const char *key,
|
||||
char *buf, size_t size)
|
||||
{
|
||||
#if defined(RARCH_CONSOLE)
|
||||
return config_get_array(conf, key, buf, size);
|
||||
if (config_get_array(conf, key, buf, size))
|
||||
return true;
|
||||
#else
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
if (entry)
|
||||
{
|
||||
fill_pathname_expand_special(buf, entry->value, size);
|
||||
|
||||
return entry != NULL;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
||||
@ -911,9 +929,7 @@ bool config_file_write(config_file_t *conf, const char *path)
|
||||
config_file_dump(conf, filestream_get_fp(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
config_file_dump(conf, stdout);
|
||||
}
|
||||
|
||||
if (file)
|
||||
filestream_close(file);
|
||||
|
Loading…
x
Reference in New Issue
Block a user