diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index c133903c75..7cbb41e5b3 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -95,11 +95,10 @@ end: * Returns: pointer to the delimiter in the path if it contains * a compressed file, otherwise NULL. */ -char *path_get_archive_delim(const char *path) +const char *path_get_archive_delim(const char *path) { - const char *last = find_last_slash(path); - #ifdef HAVE_COMPRESSION + const char *last = find_last_slash(path); char *delim = NULL; #ifdef HAVE_ZLIB @@ -483,7 +482,7 @@ void path_basedir(char *path) #ifdef HAVE_COMPRESSION /* We want to find the directory with the zipfile in basedir. */ - last = path_get_archive_delim(path); + last = path + (path_get_archive_delim(path) - path); if (last) *last = '\0'; #endif @@ -528,7 +527,7 @@ const char *path_basename(const char *path) const char *delim = path_get_archive_delim(path); if (delim) - return last + 1; + return delim + 1; #endif if (last) @@ -724,15 +723,15 @@ void fill_short_pathname_representation(char* out_rep, { char path_short[PATH_MAX_LENGTH] = {0}; #ifdef HAVE_COMPRESSION - char *last_hash = NULL; + char *last_slash = NULL; #endif fill_pathname(path_short, path_basename(in_path), "", sizeof(path_short)); #ifdef HAVE_COMPRESSION - last_hash = find_last_slash(path_short); - if(last_hash != NULL) + last_slash = find_last_slash(path_short); + if(last_slash != NULL) { /* We handle paths like: * /path/to/file.7z#mygame.img @@ -741,8 +740,8 @@ void fill_short_pathname_representation(char* out_rep, * We check whether something is actually * after the hash to avoid going over the buffer. */ - retro_assert(strlen(last_hash) > 1); - strlcpy(out_rep, last_hash + 1, size); + retro_assert(strlen(last_slash) > 1); + strlcpy(out_rep, last_slash + 1, size); } else #endif diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 43dd176138..a9fb9b1341 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -94,7 +94,7 @@ bool path_file_exists(const char *path); * Returns: pointer to the delimiter in the path if it contains * a compressed file, otherwise NULL. */ -char *path_get_archive_delim(const char *path); +const char *path_get_archive_delim(const char *path); /** * path_get_extension: diff --git a/libretro-common/include/lists/string_list.h b/libretro-common/include/lists/string_list.h index 7018c6b224..0079bd6d9b 100644 --- a/libretro-common/include/lists/string_list.h +++ b/libretro-common/include/lists/string_list.h @@ -113,15 +113,15 @@ bool string_list_append(struct string_list *list, const char *elem, * string_list_append_n: * @list : pointer to string list * @elem : element to add to the string list - * @attr : attributes of new element. * @length : read at most this many bytes from elem + * @attr : attributes of new element. * * Appends a new element to the string list. * * Returns: true (1) if successful, otherwise false (0). **/ bool string_list_append_n(struct string_list *list, const char *elem, - union string_list_elem_attr attr, unsigned length); + unsigned length, union string_list_elem_attr attr); /** * string_list_free diff --git a/libretro-common/lists/string_list.c b/libretro-common/lists/string_list.c index f0400f8363..2e82d22a14 100644 --- a/libretro-common/lists/string_list.c +++ b/libretro-common/lists/string_list.c @@ -134,15 +134,15 @@ bool string_list_append(struct string_list *list, const char *elem, * string_list_append_n: * @list : pointer to string list * @elem : element to add to the string list - * @attr : attributes of new element. * @length : read at most this many bytes from elem + * @attr : attributes of new element. * * Appends a new element to the string list. * * Returns: true (1) if successful, otherwise false (0). **/ bool string_list_append_n(struct string_list *list, const char *elem, - union string_list_elem_attr attr, unsigned length) + unsigned length, union string_list_elem_attr attr) { char *data_dup = NULL; @@ -152,11 +152,11 @@ bool string_list_append_n(struct string_list *list, const char *elem, data_dup = (char*)malloc(length + 1); - strlcpy(data_dup, elem, length + 1); - if (!data_dup) return false; + strlcpy(data_dup, elem, length + 1); + list->elems[list->size].data = data_dup; list->elems[list->size].attr = attr; diff --git a/tasks/task_content.c b/tasks/task_content.c index e7d3a7dfd7..b8654ab753 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -328,14 +328,12 @@ struct string_list *filename_split_archive(const char *path) memset(&attr, 0, sizeof(attr)); #ifdef HAVE_COMPRESSION - char *delim = path_get_archive_delim(path); + const char *delim = path_get_archive_delim(path); if (delim) { // add archive path to list first - *delim = '\0'; - - if (!string_list_append_n(list, path, attr, delim - path)) + if (!string_list_append_n(list, path, delim - path, attr)) goto error; // now add the path within the archive @@ -346,14 +344,11 @@ struct string_list *filename_split_archive(const char *path) if (!string_list_append(list, delim, attr)) goto error; } - }else{ + } + else +#endif if (!string_list_append(list, path, attr)) goto error; - } -#else - if (!string_list_append(list, path, attr)) - goto error; -#endif return list;