From 29c89a46f18b7aca6acb9d8464df53ae257c601f Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sat, 15 Jun 2024 15:35:26 +0200 Subject: [PATCH] file_archive_get_file_list_cb - remove string_list usage --- libretro-common/file/archive_file.c | 56 ++++++++++++++++------------- libretro-common/lists/nested_list.c | 2 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 40ece85ab5..705a76c476 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -55,37 +55,43 @@ static int file_archive_get_file_list_cb( if (valid_exts) { - size_t path_len = strlen(path); - /* Checks if this entry is a directory or a file. */ - char last_char = path[path_len - 1]; - struct string_list ext_list = {0}; + char *tok, *save; + bool found_ext = false; + char *valid_exts_cpy = NULL; + size_t path_len = 0; + char last_char = 0; + const char *file_ext = path_get_extension(path); - /* Skip if directory. */ - if (last_char == '/' || last_char == '\\' ) + if (!file_ext) return 1; - - string_list_initialize(&ext_list); - if (string_split_noalloc(&ext_list, valid_exts, "|")) + + path_len = strlen(path); + last_char = path[path_len - 1]; + + /* Checks if this entry is a directory or a file. */ + /* Skip if directory. */ + if (last_char == '/' || last_char == '\\') + return 1; + + valid_exts_cpy = strdup(valid_exts); + tok = strtok_r(valid_exts_cpy, "|", &save); + + while (tok) { - const char *file_ext = path_get_extension(path); - - if (!file_ext) + if (string_is_equal_noncase(tok, file_ext)) { - string_list_deinitialize(&ext_list); - return 1; + found_ext = true; + break; } - - if (!string_list_find_elem_prefix(&ext_list, ".", file_ext)) - { - /* keep iterating */ - string_list_deinitialize(&ext_list); - return -1; - } - - attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE; + tok = strtok_r(NULL, "|", &save); } + free(valid_exts_cpy); - string_list_deinitialize(&ext_list); + /* keep iterating */ + if (!found_ext) + return -1; + + attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE; } return string_list_append(userdata->list, path, attr); @@ -531,7 +537,7 @@ int file_archive_compressed_read( const char * path, void **buf, const char* optional_filename, int64_t *length) { - const struct + const struct file_archive_file_backend *backend = NULL; struct string_list *str_list = NULL; diff --git a/libretro-common/lists/nested_list.c b/libretro-common/lists/nested_list.c index a57858cfa9..b05b1ae889 100644 --- a/libretro-common/lists/nested_list.c +++ b/libretro-common/lists/nested_list.c @@ -518,7 +518,7 @@ const char *nested_list_item_get_id(nested_list_item_t *list_item) * @address : a delimited list of item identifiers, * corresponding to item 'levels' * @len : length of supplied @address char array - + * Fetches a compound @address string corresponding to * the specified item's 'position' in the top level * nested list of which it is a member. The resultant