From 60288c1ea73d6ee3da2ab7d284447dd25589a0ae Mon Sep 17 00:00:00 2001
From: Thomas Huth
Date: Sun, 1 Nov 2026 14:15:43 +0100
Subject: [PATCH] Check whether libretro.h supports the v4 retro_vfs_stat_64_t
interface
Disable the corresponding code if it's not available, so we can
finally enable the vfs.c code in the normal build, too.
---
CMakeLists.txt | 6 ++++++
cmake/config-cmake.h | 3 +++
src/retro/CMakeLists.txt | 17 +++++++++++++++--
src/retro/main_retro.c | 2 +-
src/retro/vfs.c | 34 +++++++++++++++++++---------------
tests/retro/test-retro.c | 1 +
6 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 355228ff8..1ac185c23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -260,6 +260,12 @@ check_symbol_exists(ftello "stdio.h" HAVE_FTELLO)
check_symbol_exists(flock "sys/file.h" HAVE_FLOCK)
check_struct_has_member("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)
+if(ENABLE_LIBRETRO)
+ check_struct_has_member("struct retro_vfs_interface" stat_64
+ "${LIBRETRO_INCLUDE_DIR}/libretro.h"
+ HAVE_RETRO_VFS_STAT_64_T)
+endif(ENABLE_LIBRETRO)
+
# #############
# Other CFLAGS:
# #############
diff --git a/cmake/config-cmake.h b/cmake/config-cmake.h
index e1ef51f00..326594c83 100644
--- a/cmake/config-cmake.h
+++ b/cmake/config-cmake.h
@@ -99,6 +99,9 @@
/* Define to 1 if you have the 'd_type' member in the 'dirent' struct */
#cmakedefine HAVE_DIRENT_D_TYPE 1
+/* Define to 1 if you have the retro_vfs_stat_64_t in libretro.h */
+#cmakedefine HAVE_RETRO_VFS_STAT_64_T 1
+
/* Relative path from bindir to datadir */
#define BIN2DATADIR "@BIN2DATADIR@"
diff --git a/src/retro/CMakeLists.txt b/src/retro/CMakeLists.txt
index 40515346d..9a7a5ff2d 100644
--- a/src/retro/CMakeLists.txt
+++ b/src/retro/CMakeLists.txt
@@ -1,7 +1,20 @@
include_directories(. ../.. ../includes ../debug ../falcon)
-add_library(UiRetro OBJECT audio.c disk_control.c harddisk.c joy_ui.c gui_event.c keymap.c
- main_retro.c microphone.c options.c screen.c statusbar.c timing.c)
+add_library(UiRetro OBJECT
+ audio.c
+ disk_control.c
+ harddisk.c
+ joy_ui.c
+ gui_event.c
+ keymap.c
+ main_retro.c
+ microphone.c
+ options.c
+ screen.c
+ statusbar.c
+ timing.c
+ vfs.c)
+
target_include_directories(UiRetro PRIVATE ${LIBRETRO_INCLUDE_DIR})
set_target_properties(UiRetro PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
diff --git a/src/retro/main_retro.c b/src/retro/main_retro.c
index f90c04a07..91cfa7607 100644
--- a/src/retro/main_retro.c
+++ b/src/retro/main_retro.c
@@ -145,7 +145,7 @@ RETRO_API void retro_set_environment(retro_environment_t cb)
libretro_set_core_options(cb, &categories_supported);
/* Retrieve VFS interface v4 or fall back if not available */
- //VFS_Init();
+ VFS_Init();
}
RETRO_API void retro_set_video_refresh(retro_video_refresh_t cb)
diff --git a/src/retro/vfs.c b/src/retro/vfs.c
index f0cc4e019..f6f403516 100644
--- a/src/retro/vfs.c
+++ b/src/retro/vfs.c
@@ -223,29 +223,34 @@ int64_t VFS_fsize(VFS_FILE stream)
bool VFS_FileExists(const char *path)
{
+ struct stat st;
+
+#if HAVE_RETRO_VFS_STAT_64_T
if (VFS_IsActive() && vfs_iface->stat_64)
{
int64_t size = 0;
int flags = vfs_iface->stat_64(path, &size);
return (flags & RETRO_VFS_STAT_IS_VALID) && !(flags & RETRO_VFS_STAT_IS_DIRECTORY);
}
+#endif
// fallback
- {
- struct stat st;
- return (stat(path, &st) == 0 &&
- (st.st_mode & (S_IRUSR|S_IWUSR)) && !S_ISDIR(st.st_mode));
- }
+ return (stat(path, &st) == 0 &&
+ (st.st_mode & (S_IRUSR|S_IWUSR)) && !S_ISDIR(st.st_mode));
}
bool VFS_DirExists(const char *path)
{
+ struct stat st;
+
+#if HAVE_RETRO_VFS_STAT_64_T
if (VFS_IsActive() && vfs_iface->stat_64)
{
int64_t size = 0;
int flags = vfs_iface->stat_64(path, &size);
return (flags & RETRO_VFS_STAT_IS_VALID) && (flags & RETRO_VFS_STAT_IS_DIRECTORY);
}
+#endif
if (VFS_IsActive() && vfs_iface->opendir && vfs_iface->closedir)
{
@@ -257,26 +262,25 @@ bool VFS_DirExists(const char *path)
}
// fallback
- {
- struct stat st;
- return (stat(path, &st) == 0 && S_ISDIR(st.st_mode));
- }
+ return (stat(path, &st) == 0 && S_ISDIR(st.st_mode));
}
int64_t VFS_FileLength(const char *path)
{
+ struct stat st;
+
+#if HAVE_RETRO_VFS_STAT_64_T
if (VFS_IsActive() && vfs_iface->stat_64)
{
int64_t size = 0;
int flags = vfs_iface->stat_64(path, &size);
return (flags & RETRO_VFS_STAT_IS_VALID) ? (int64_t)size : -1;
}
+#endif
// fallback
- {
- struct stat st;
- if (stat(path, &st) == 0)
- return (int64_t)st.st_size;
- return -1;
- }
+ if (stat(path, &st) == 0)
+ return (int64_t)st.st_size;
+
+ return -1;
}
diff --git a/tests/retro/test-retro.c b/tests/retro/test-retro.c
index 4a21f371c..51656ac4c 100644
--- a/tests/retro/test-retro.c
+++ b/tests/retro/test-retro.c
@@ -80,6 +80,7 @@ static bool env_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY:
case RETRO_ENVIRONMENT_GET_VARIABLE:
case RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE:
+ case RETRO_ENVIRONMENT_GET_VFS_INTERFACE:
return false;
case RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE:
case RETRO_ENVIRONMENT_SET_GEOMETRY: