Util: Clean up VFileOpen backing a bit more

This commit is contained in:
Vicki Pfau 2024-05-07 22:02:49 -07:00
parent d9e080b9a9
commit ff2dfeb516
7 changed files with 24 additions and 9 deletions

View File

@ -207,6 +207,7 @@ elseif(BUILD_PGO AND PGO_STAGE_2)
endif()
# Platform support
set(OS_DEFINES)
if(WIN32)
set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
@ -220,6 +221,7 @@ if(WIN32)
endif()
endif()
list(APPEND OS_LIB ws2_32 shlwapi)
list(APPEND OS_DEFINES ENABLE_VFS_FD)
list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/vfs-w32.c)
file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c)
source_group("Windows-specific code" FILES ${OS_SRC})
@ -230,6 +232,7 @@ elseif(UNIX)
add_definitions(-D_GNU_SOURCE)
endif()
list(APPEND OS_DEFINES ENABLE_VFS_FD)
list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/posix/*.c)
source_group("POSIX-specific code" FILES ${OS_SRC})
@ -858,7 +861,6 @@ source_group("Extra features" FILES ${FEATURE_SRC})
source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
# Platform binaries
set(OS_DEFINES)
if(DEFINED 3DS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/3ds ${CMAKE_CURRENT_BINARY_DIR}/3ds)
endif()

View File

@ -66,11 +66,18 @@ struct VDir {
};
struct VFile* VFileOpen(const char* path, int flags);
#endif
#ifdef ENABLE_VFS_FD
struct VFile* VFileOpenFD(const char* path, int flags);
struct VFile* VFileFromFD(int fd);
#endif
#ifdef ENABLE_VFS_FILE
struct VFile* VFileFOpen(const char* path, const char* mode);
struct VFile* VFileFromFILE(FILE* file);
#endif
struct VFile* VFileFromMemory(void* mem, size_t size);
struct VFile* VFileFromConstMemory(const void* mem, size_t size);
struct VFile* VFileMemChunk(const void* mem, size_t size);
@ -97,11 +104,6 @@ struct VDir* VDeviceList(void);
bool VDirCreate(const char* path);
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*));
struct VFile* VDirFindNextAvailable(struct VDir*, const char* basename, const char* infix, const char* suffix, int mode);
#ifdef ENABLE_VFS_FILE
struct VFile* VFileFOpen(const char* path, const char* mode);
struct VFile* VFileFromFILE(FILE* file);
#endif
#endif
void separatePath(const char* path, char* dirname, char* basename, char* extension);

View File

@ -65,6 +65,14 @@
#cmakedefine ENABLE_VFS
#endif
#ifndef ENABLE_VFS_FD
#cmakedefine ENABLE_VFS_FD
#endif
#ifndef ENABLE_VFS_FILE
#cmakedefine ENABLE_VFS_FILE
#endif
// USE flags
#ifndef USE_DISCORD_RPC

View File

@ -31,6 +31,7 @@ source_group("3DS-specific code" FILES ${OS_SRC})
if(ENABLE_VFS_3DS)
list(APPEND OS_DEFINES ENABLE_VFS_3DS)
else()
list(APPEND OS_DEFINES ENABLE_VFS_FD)
list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
endif()
set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)

View File

@ -4,7 +4,7 @@ find_program(BUILD_ROMFS build_romfs)
find_library(GLAPI_LIBRARY glapi REQUIRED)
find_library(EGL_LIBRARY EGL REQUIRED)
set(OS_DEFINES _GNU_SOURCE IOAPI_NO_64)
set(OS_DEFINES _GNU_SOURCE IOAPI_NO_64 ENABLE_VFS_FD)
list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)

View File

@ -8,7 +8,7 @@ if(WIIDRC_LIBRARY)
add_definitions(-DWIIDRC)
endif()
set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 IOAPI_NO_64 FIXED_ROM_BUFFER)
set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 IOAPI_NO_64 FIXED_ROM_BUFFER ENABLE_VFS_FD)
list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-devlist.c)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

View File

@ -96,8 +96,10 @@ struct VFile* VFileOpen(const char* path, int flags) {
vf->seek(vf, vf->size(vf), SEEK_SET);
}
return vf;
#else
#elif defined(ENABLE_VFS_FD)
return VFileOpenFD(path, flags);
#else
#error "Can't build VFS subsystem without a VFile backend"
#endif
}