mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Simplify config_file_write
This commit is contained in:
parent
513885d465
commit
a4500eeafc
@ -902,32 +902,9 @@ void config_set_bool(config_file_t *conf, const char *key, bool val)
|
||||
config_set_string(conf, key, val ? "true" : "false");
|
||||
}
|
||||
|
||||
bool config_file_write(config_file_t *conf, const char *path)
|
||||
{
|
||||
if (!string_is_empty(path))
|
||||
{
|
||||
void* buf = NULL;
|
||||
FILE *file = fopen_utf8(path, "wb");
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
/* TODO: this is only useful for a few platforms, find which and add ifdef */
|
||||
buf = calloc(1, 0x4000);
|
||||
setvbuf(file, (char*)buf, _IOFBF, 0x4000);
|
||||
|
||||
config_file_dump(conf, file);
|
||||
|
||||
if (file != stdout)
|
||||
fclose(file);
|
||||
free(buf);
|
||||
}
|
||||
else
|
||||
config_file_dump(conf, stdout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void config_file_dump(config_file_t *conf, FILE *file)
|
||||
/* Dump the current config to an already opened file.
|
||||
* Does not close the file. */
|
||||
static void config_file_dump(config_file_t *conf, FILE *file)
|
||||
{
|
||||
struct config_entry_list *list = NULL;
|
||||
struct config_include_list *includes = conf->includes;
|
||||
@ -948,6 +925,33 @@ void config_file_dump(config_file_t *conf, FILE *file)
|
||||
}
|
||||
}
|
||||
|
||||
bool config_file_write(config_file_t *conf, const char *path)
|
||||
{
|
||||
void* buf = NULL;
|
||||
FILE *file = !string_is_empty(path) ? fopen_utf8(path, "wb") : stdout;
|
||||
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
/* TODO: this is only useful for a few platforms, find which and add ifdef */
|
||||
if (file != stdout)
|
||||
{
|
||||
buf = calloc(1, 0x4000);
|
||||
setvbuf(file, (char*)buf, _IOFBF, 0x4000);
|
||||
}
|
||||
|
||||
config_file_dump(conf, file);
|
||||
|
||||
if (file != stdout)
|
||||
{
|
||||
fclose(file);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool config_entry_exists(config_file_t *conf, const char *entry)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
|
@ -154,10 +154,6 @@ void config_set_bool(config_file_t *conf, const char *entry, bool val);
|
||||
/* Write the current config to a file. */
|
||||
bool config_file_write(config_file_t *conf, const char *path);
|
||||
|
||||
/* Dump the current config to an already opened file.
|
||||
* Does not close the file. */
|
||||
void config_file_dump(config_file_t *conf, FILE *file);
|
||||
|
||||
bool config_file_exists(const char *path);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
Loading…
x
Reference in New Issue
Block a user