diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 5c26178ff9..45fabd4115 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -384,15 +384,18 @@ char *find_last_slash(const char *str) **/ size_t fill_pathname_slash(char *s, size_t len) { - char *last_slash = find_last_slash(s); + char *last_slash = find_last_slash(s); + len = strlen(s); if (!last_slash) - return strlcat(s, PATH_DEFAULT_SLASH(), len); - len = strlen(s); - /* Try to preserve slash type. */ - if (last_slash != (s + len - 1)) { - s[ len] = last_slash[0]; - s[++len] = '\0'; + s[ len] = PATH_DEFAULT_SLASH_C(); + s[++len] = '\0'; + } + else if (last_slash != (s + len - 1)) + { + /* Try to preserve slash type. */ + s[ len] = last_slash[0]; + s[++len] = '\0'; } return len; } @@ -992,20 +995,17 @@ size_t fill_pathname_join_special(char *s, if (*s) { - char *last_slash = find_last_slash(s); - if (last_slash) + char *last_slash = find_last_slash(s); + if (!last_slash) + { + s[ _len] = PATH_DEFAULT_SLASH_C(); + s[++_len] = '\0'; + } + else if (last_slash != (s + _len - 1)) { /* Try to preserve slash type. */ - if (last_slash != (s + _len - 1)) - { - s[ _len] = last_slash[0]; - s[++_len] = '\0'; - } - } - else - { - s[ _len] = PATH_DEFAULT_SLASH_C(); - s[++_len] = '\0'; + s[ _len] = last_slash[0]; + s[++_len] = '\0'; } } @@ -1327,14 +1327,14 @@ void path_basedir_wrapper(char *s) *last_slash = '\0'; #endif last_slash = find_last_slash(s); - if (last_slash) - last_slash[1] = '\0'; - else + if (!last_slash) { s[0] = '.'; s[1] = PATH_DEFAULT_SLASH_C(); s[2] = '\0'; } + else + last_slash[1] = '\0'; } #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)