From 34ce65d9c41e87a0a28569931a22c22fa663b4c7 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 6 Oct 2013 12:16:44 +0200 Subject: [PATCH] Rework extension files to only consider basename. Only consider last '.' in the basename of a file. --- core_info.c | 21 ++++----------------- file.h | 6 +++++- file_path.c | 6 +++--- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/core_info.c b/core_info.c index 3d4ac890d2..6ebf5cf510 100644 --- a/core_info.c +++ b/core_info.c @@ -47,31 +47,18 @@ core_info_list_t *core_info_list_new(const char *modules_path) for (size_t i = 0; i < contents->size; i++) { -#if 0 - char buffer[PATH_MAX]; char info_path[PATH_MAX]; - core_info[i].path = strdup(contents->elems[i].data); - // FIXME: Need to do something about this logic. - // fill_pathname() *should* be sufficient. - // - // NOTE: This assumes all modules are named module_name_{tag}.ext - // {tag} must not contain an underscore. (This isn't true for PC versions) +#if defined(IOS) || defined(HAVE_BB10) || defined(__QNX__) + // Libs are deployed with a suffix (*_ios.dylib, *_qnx.so, etc). + char buffer[PATH_MAX]; strlcpy(buffer, contents->elems[i].data, sizeof(buffer)); char *substr = strrchr(buffer, '_'); if (substr) *substr = '\0'; - - // NOTE: Can't just use fill_pathname on iOS as it will cut at RetroArch.app; - // perhaps fill_pathname shouldn't cut before the last path element. - if (substr) - snprintf(info_path, PATH_MAX, "%s.info", buffer); - else - fill_pathname(info_path, buffer, ".info", sizeof(info_path)); + fill_pathname(info_path, buffer, ".info", sizeof(info_path)); #else - core_info[i].path = strdup(contents->elems[i].data); - char info_path[PATH_MAX]; fill_pathname(info_path, core_info[i].path, ".info", sizeof(info_path)); #endif diff --git a/file.h b/file.h index 880734f715..854c515373 100644 --- a/file.h +++ b/file.h @@ -74,11 +74,14 @@ void string_list_free(struct string_list *list); bool path_is_directory(const char *path); bool path_file_exists(const char *path); + +// Gets extension of file. Only '.'s after the last slash are considered. const char *path_get_extension(const char *path); bool path_mkdir(const char *dir); -// Removes all text after and including the last '.' +// Removes all text after and including the last '.'. +// Only '.'s after the last slash are considered. char *path_remove_extension(char *path); // Returns basename from path. @@ -102,6 +105,7 @@ bool path_is_absolute(const char *path); // Replaces filename extension with 'replace' and outputs result to out_path. // The extension here is considered to be the string from the last '.' to the end. +// Only '.'s after the last slash are considered as extensions. // If no '.' is present, in_path and replace will simply be concatenated. // 'size' is buffer size of 'out_path'. // E.g.: in_path = "/foo/bar/baz/boo.c", replace = ".asm" => out_path = "/foo/bar/baz/boo.asm" diff --git a/file_path.c b/file_path.c index c782585970..a535cc21ae 100644 --- a/file_path.c +++ b/file_path.c @@ -180,7 +180,7 @@ bool string_list_find_elem_prefix(const struct string_list *list, const char *pr const char *path_get_extension(const char *path) { - const char *ext = strrchr(path, '.'); + const char *ext = strrchr(path_basename(path), '.'); if (ext) return ext + 1; else @@ -189,7 +189,7 @@ const char *path_get_extension(const char *path) char *path_remove_extension(char *path) { - char *last = strrchr(path, '.'); + char *last = strrchr(path_basename(path), '.'); if (*last) *last = '\0'; return last; @@ -417,7 +417,7 @@ void fill_pathname(char *out_path, const char *in_path, const char *replace, siz char tmp_path[PATH_MAX]; rarch_assert(strlcpy(tmp_path, in_path, sizeof(tmp_path)) < sizeof(tmp_path)); - char *tok = strrchr(tmp_path, '.'); + char *tok = strrchr(path_basename(tmp_path), '.'); if (tok) *tok = '\0';