diff --git a/input/input_autodetect.c b/input/input_autodetect.c index ce396d6541..98e93881dc 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -230,10 +230,18 @@ static bool input_autoconfigure_joypad_from_conf_dir( if(index >= 0 && current_best > 0) { conf = config_file_new(list->elems[index].data); - RARCH_LOG("Autodetect: selected configuration: %s\n", conf->path); - input_autoconfigure_joypad_add(conf, params); - config_file_free(conf); - ret = 1; + + if (conf) + { + char conf_path[PATH_MAX_LENGTH]; + + config_get_config_path(conf, conf_path, sizeof(conf_path)); + + RARCH_LOG("Autodetect: selected configuration: %s\n", conf_path); + input_autoconfigure_joypad_add(conf, params); + config_file_free(conf); + ret = 1; + } } else ret = 0; diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index e0903f7c7c..d16facdf57 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -47,6 +47,34 @@ #define MAX_INCLUDE_DEPTH 16 +struct config_entry_list +{ + /* If we got this from an #include, + * do not allow overwrite. */ + bool readonly; + char *key; + char *value; + uint32_t key_hash; + + struct config_entry_list *next; +}; + +struct config_include_list +{ + char *path; + struct config_include_list *next; +}; + +struct config_file +{ + char *path; + struct config_entry_list *entries; + struct config_entry_list *tail; + unsigned include_depth; + + struct config_include_list *includes; +}; + static config_file_t *config_file_new_internal(const char *path, unsigned depth); void config_file_free(config_file_t *conf); @@ -662,6 +690,14 @@ bool config_get_string(config_file_t *conf, const char *key, char **str) return entry != NULL; } +bool config_get_config_path(config_file_t *conf, char *s, size_t len) +{ + if (!conf) + return false; + + return strlcpy(s, conf->path, len); +} + bool config_get_array(config_file_t *conf, const char *key, char *buf, size_t size) { diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index 8a3ad49b61..c507198123 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -34,34 +34,6 @@ extern "C" { #include -struct config_entry_list -{ - /* If we got this from an #include, - * do not allow overwrite. */ - bool readonly; - char *key; - char *value; - uint32_t key_hash; - - struct config_entry_list *next; -}; - -struct config_include_list -{ - char *path; - struct config_include_list *next; -}; - -struct config_file -{ - char *path; - struct config_entry_list *entries; - struct config_entry_list *tail; - unsigned include_depth; - - struct config_include_list *includes; -}; - typedef struct config_file config_file_t; /* Config file format @@ -132,11 +104,14 @@ bool config_get_char(config_file_t *conf, const char *entry, char *in); bool config_get_string(config_file_t *conf, const char *entry, char **in); /* Extracts a string to a preallocated buffer. Avoid memory allocation. */ -bool config_get_array(config_file_t *conf, const char *entry, char *in, size_t size); +bool config_get_array(config_file_t *conf, const char *entry, char *s, size_t len); /* Extracts a string to a preallocated buffer. Avoid memory allocation. * Recognized magic like ~/. Similar to config_get_array() otherwise. */ -bool config_get_path(config_file_t *conf, const char *entry, char *in, size_t size); +bool config_get_path(config_file_t *conf, const char *entry, char *s, size_t len); + +/* Extracts a string to a preallocated buffer. Avoid memory allocation. */ +bool config_get_config_path(config_file_t *conf, char *s, size_t len); /* Extracts a boolean from config. * Valid boolean true are "true" and "1". Valid false are "false" and "0".