diff --git a/components/retro-go/rg_utils.c b/components/retro-go/rg_utils.c index 3fa40116c..3313998c8 100644 --- a/components/retro-go/rg_utils.c +++ b/components/retro-go/rg_utils.c @@ -62,18 +62,20 @@ const char *rg_extension(const char *filename) { if (!filename) return NULL; - - const char *ptr = rg_basename(filename); - const char *ext = strrchr(ptr, '.'); - if (!ext) - return ptr + strlen(ptr); - return ext + 1; + const char *ptr = filename + strlen(filename) - 1; + while (ptr > filename && *ptr != '/') + { + if (*ptr == '.') + return ptr + 1; + ptr--; + } + return NULL; } bool rg_extension_match(const char *filename, const char *extensions) { const char *ext = rg_extension(filename); - if (!ext || !*ext || !extensions || !*extensions) + if (!ext || !extensions) return false; const char *haystack = extensions;