From b431285819450fb77e7cdf75f95ae1b96ce4c600 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 5 Oct 2020 15:14:52 +0100 Subject: [PATCH] (GEKKO) Remove trailing slash when calling retro_vfs_stat_impl() --- libretro-common/vfs/vfs_implementation.c | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 5f3a7ef07d..b710e2f0bb 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -975,6 +975,40 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) *size = (int32_t)buf.st_size; is_dir = (file_info & FILE_ATTRIBUTE_DIRECTORY); + +#elif defined(GEKKO) + /* On GEKKO platforms, paths cannot have + * trailing slashes - we must therefore + * remove them */ + char *path_buf = NULL; + int stat_ret = -1; + struct stat stat_buf; + size_t len; + + if (string_is_empty(path)) + return 0; + + path_buf = strdup(path); + if (!path_buf) + return 0; + + len = strlen(path_buf); + if (len > 0) + if (path_buf[len - 1] == '/') + path_buf[len - 1] = '\0'; + + stat_ret = stat(path_buf, &stat_buf); + free(path_buf); + + if (stat_ret < 0) + return 0; + + if (size) + *size = (int32_t)stat_buf.st_size; + + is_dir = S_ISDIR(stat_buf.st_mode); + is_character_special = S_ISCHR(stat_buf.st_mode); + #else /* Every other platform */ struct stat buf;