From 3c06a907cafc248603de7610b93384df76581c7a Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 5 Oct 2020 10:59:55 +0100 Subject: [PATCH] Fix directory creation on GEKKO platforms when path contains a trailing slash --- libretro-common/file/file_path_io.c | 14 -------------- libretro-common/vfs/vfs_implementation.c | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libretro-common/file/file_path_io.c b/libretro-common/file/file_path_io.c index 71b85b1010..413228fab8 100644 --- a/libretro-common/file/file_path_io.c +++ b/libretro-common/file/file_path_io.c @@ -197,20 +197,6 @@ bool path_mkdir(const char *dir) return false; } -#if defined(GEKKO) - { - size_t len = strlen(basedir); - - /* path_parent_dir() keeps the trailing slash. - * On Wii, mkdir() fails if the path has a - * trailing slash... - * We must therefore remove it. */ - if (len > 0) - if (basedir[len - 1] == '/') - basedir[len - 1] = '\0'; - } -#endif - if (path_is_directory(basedir)) norecurse = true; else diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 637b873d99..5f3a7ef07d 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -1024,6 +1024,28 @@ int retro_vfs_mkdir_impl(const char *dir) int ret = orbisMkdir(dir, 0755); #elif defined(__QNX__) int ret = mkdir(dir, 0777); +#elif defined(GEKKO) + /* On GEKKO platforms, mkdir() fails if + * the path has a trailing slash. We must + * therefore remove it. */ + int ret = -1; + if (!string_is_empty(dir)) + { + char *dir_buf = strdup(dir); + + if (dir_buf) + { + size_t len = strlen(dir_buf); + + if (len > 0) + if (dir_buf[len - 1] == '/') + dir_buf[len - 1] = '\0'; + + ret = mkdir(dir_buf, 0750); + + free(dir_buf); + } + } #else int ret = mkdir(dir, 0750); #endif