From c2c7c106a12a5284d42ee26aa58b54de2c89d106 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 Jul 2019 00:39:55 +0200 Subject: [PATCH] Add conf->path for config_file_new_from_path_to_string --- libretro-common/file/config_file.c | 14 +++++++++----- libretro-common/include/file/config_file.h | 3 ++- tasks/task_autodetect.c | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index eb2b9abbed..dc833f7e49 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -530,7 +530,8 @@ bool config_append_file(config_file_t *conf, const char *path) return true; } -config_file_t *config_file_new_from_string(const char *from_string) +config_file_t *config_file_new_from_string(const char *from_string, + const char *path) { size_t i; struct string_list *lines = NULL; @@ -549,6 +550,9 @@ config_file_t *config_file_new_from_string(const char *from_string) conf->include_depth = 0; conf->guaranteed_no_duplicates = false ; + if (!string_is_empty(path)) + conf->path = strdup(path); + lines = string_split(from_string, "\n"); if (!lines) return conf; @@ -602,9 +606,9 @@ config_file_t *config_file_new_from_path_to_string(const char *path) if (filestream_read_file(path, (void**)&ret_buf, &length)) { if (length >= 0) - if ((conf = config_file_new_from_string((const char*)ret_buf))) - conf->path = strdup(path); - free((void*)ret_buf); + conf = config_file_new_from_string((const char*)ret_buf, path); + if ((void*)ret_buf) + free((void*)ret_buf); } return conf; @@ -1142,7 +1146,7 @@ static void test_config_file_parse_contains( const char * cfgtext, const char *key, const char *val) { - config_file_t *cfg = config_file_new_from_string(cfgtext); + config_file_t *cfg = config_file_new_from_string(cfgtext, NULL); char *out = NULL; bool ok = false; diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index d441ff5505..e13e655a90 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -94,7 +94,8 @@ config_file_t *config_file_new_alloc(void); config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb); /* Load a config file from a string. */ -config_file_t *config_file_new_from_string(const char *from_string); +config_file_t *config_file_new_from_string(const char *from_string, + const char *path); config_file_t *config_file_new_from_path_to_string(const char *path); diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index a0a745e86b..947ca1c318 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -407,7 +407,7 @@ static bool input_autoconfigure_joypad_from_conf_internal( for (i = 0; input_builtin_autoconfs[i]; i++) { config_file_t *conf = config_file_new_from_string( - input_builtin_autoconfs[i]); + input_builtin_autoconfs[i], NULL); if (conf && input_autoconfigure_joypad_from_conf(conf, params, task)) return true; }