diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 0b2f953788..fef13b5a39 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -910,11 +910,25 @@ void fill_pathname_resolve_relative(char *out_path, size_t fill_pathname_join(char *out_path, const char *dir, const char *path, size_t size) { + size_t len = 0; if (out_path != dir) - strlcpy(out_path, dir, size); + len = strlcpy(out_path, dir, size); if (*out_path) - fill_pathname_slash(out_path, size); + { + const char *last_slash = find_last_slash(out_path); + if (last_slash) + { + /* Try to preserve slash type. */ + if (last_slash != (out_path + len - 1)) + { + out_path[len] = last_slash[0]; + out_path[len+1] = '\0'; + } + } + else + strlcat(out_path, PATH_DEFAULT_SLASH(), size); + } return strlcat(out_path, path, size); } diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 17ca9ded3c..8613e8c9ff 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -446,12 +446,12 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, * @size : size of output path * * Joins a directory (@dir) and path (@path) together. - * Makes sure not to get two consecutive slashes + * Makes sure not to get two consecutive slashes * between directory and path. * * Hidden non-leaf function cost: * - calls strlcpy - * - calls fill_pathname_slash() + * - calls find_last_slash() * - calls strlcat **/ size_t fill_pathname_join(char *out_path, const char *dir,