diff --git a/core_info.c b/core_info.c index acafdc2031..b2aaa5a0b8 100644 --- a/core_info.c +++ b/core_info.c @@ -286,7 +286,7 @@ static core_info_list_t *core_info_list_new(const char *path, char *tmp = NULL; bool tmp_bool = false; unsigned count = 0; - config_file_t *conf = config_file_new(info_path); + config_file_t *conf = config_file_read(info_path); free(info_path); diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 3557f322ad..cdfe1c2f5e 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -69,7 +69,7 @@ struct config_include_list }; static config_file_t *config_file_new_internal( - const char *path, unsigned depth, config_file_cb_t *cb); + const char *path, unsigned depth, config_file_cb_t *cb, bool no_checks); static int config_sort_compare_func(struct config_entry_list *a, struct config_entry_list *b) @@ -270,7 +270,8 @@ static void add_child_list(config_file_t *parent, config_file_t *child) parent->tail = NULL; } -static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) +static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb, + bool no_checks) { char real_path[PATH_MAX_LENGTH]; config_file_t *sub_conf = NULL; @@ -317,7 +318,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) #endif sub_conf = (config_file_t*) - config_file_new_internal(real_path, conf->include_depth + 1, cb); + config_file_new_internal(real_path, conf->include_depth + 1, cb, no_checks); if (!sub_conf) return; @@ -327,18 +328,14 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) } static bool parse_line(config_file_t *conf, - struct config_entry_list *list, char *line, config_file_cb_t *cb) + struct config_entry_list *list, char *line, config_file_cb_t *cb, + bool no_checks) { - char *comment = NULL; char *key_tmp = NULL; size_t cur_size = 8; size_t idx = 0; char *key = (char*)malloc(9); - - if (!key) - return false; - - comment = strip_comment(line); + char *comment = strip_comment(line); /* Starting line with #include includes config files. */ if (comment == line) @@ -354,7 +351,7 @@ static bool parse_line(config_file_t *conf, if (conf->include_depth >= MAX_INCLUDE_DEPTH) fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n"); else - add_sub_conf(conf, path, cb); + add_sub_conf(conf, path, cb, no_checks); free(path); } goto error; @@ -399,7 +396,7 @@ error: } static config_file_t *config_file_new_internal( - const char *path, unsigned depth, config_file_cb_t *cb) + const char *path, unsigned depth, config_file_cb_t *cb, bool no_checks) { RFILE *file = NULL; struct config_file *conf = (struct config_file*)malloc(sizeof(*conf)); @@ -417,8 +414,9 @@ static config_file_t *config_file_new_internal( if (!path || !*path) return conf; #if !defined(ORBIS) - if (path_is_directory(path)) - goto error; + if (!no_checks) + if (path_is_directory(path)) + goto error; #endif conf->path = strdup(path); if (!conf->path) @@ -460,7 +458,7 @@ static config_file_t *config_file_new_internal( continue; } - if (*line && parse_line(conf, list, line, cb)) + if (*line && parse_line(conf, list, line, cb, no_checks)) { if (conf->entries) conf->tail->next = list; @@ -550,8 +548,9 @@ bool config_append_file(config_file_t *conf, const char *path) config_file_t *config_file_new_from_string(const char *from_string) { size_t i; + bool no_checks = false; struct string_list *lines = NULL; - struct config_file *conf = (struct config_file*)malloc(sizeof(*conf)); + struct config_file *conf = (struct config_file*)malloc(sizeof(*conf)); if (!conf) return NULL; @@ -589,7 +588,7 @@ config_file_t *config_file_new_from_string(const char *from_string) if (line && conf) { - if (*line && parse_line(conf, list, line, NULL)) + if (*line && parse_line(conf, list, line, NULL, no_checks)) { if (conf->entries) conf->tail->next = list; @@ -611,11 +610,16 @@ config_file_t *config_file_new_from_string(const char *from_string) config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb) { - return config_file_new_internal(path, 0, cb); + return config_file_new_internal(path, 0, cb, false); } config_file_t *config_file_new(const char *path) { - return config_file_new_internal(path, 0, NULL); + return config_file_new_internal(path, 0, NULL, false); +} + +config_file_t *config_file_read(const char *path) +{ + return config_file_new_internal(path, 0, NULL, true); } static struct config_entry_list *config_get_entry(const config_file_t *conf, diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index e4e7eb585d..6174907c37 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -86,6 +86,11 @@ typedef struct config_file_cb config_file_cb_t ; * NULL path will create an empty config file. */ config_file_t *config_file_new(const char *path); +/* Is the same as config_file_new, with the only difference that + * it doesn't check if the path provided is a directory. This can + * be significantly faster on platforms where file I/O is slow */ +config_file_t *config_file_read(const char *path); + /* Loads a config file. Returns NULL if file doesn't exist. * NULL path will create an empty config file. * Includes cb callbacks to run custom code during config file processing.*/