From e5215d9e2975832879879099abc2c5741e88413b Mon Sep 17 00:00:00 2001 From: Manuel Alfayate Corchete Date: Mon, 20 Dec 2021 22:24:19 +0000 Subject: [PATCH] Fix incorrect file names for remap files when the content path doesn't have a preceding slash. (#13385) --- libretro-common/file/file_path.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index a12be47ab2..926e837ad4 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -407,15 +407,29 @@ bool fill_pathname_parent_dir_name(char *out_dir, last = find_last_slash(temp); } + /* Cut the last part of the string (the filename) after the slash, + leaving the directory name (or nested directory names) only. */ if (last) *last = '\0'; + /* Point in_dir to the address of the last slash. */ in_dir = find_last_slash(temp); + /* If find_last_slash returns NULL, it means there was no slash in temp, + so use temp as-is. */ + if (!in_dir) + in_dir = temp; + success = in_dir && in_dir[1]; if (success) - strlcpy(out_dir, in_dir + 1, size); + { + /* If path starts with an slash, eliminate it. */ + if (path_is_absolute(in_dir)) + strlcpy(out_dir, in_dir + 1, size); + else + strlcpy(out_dir, in_dir, size); + } free(temp); return success;