diff --git a/dep/libchdr/CMakeLists.txt b/dep/libchdr/CMakeLists.txt index 05b8c7ad..90ec441b 100644 --- a/dep/libchdr/CMakeLists.txt +++ b/dep/libchdr/CMakeLists.txt @@ -14,6 +14,9 @@ add_library(libchdr src/libchdr_huffman.c ) -target_include_directories(libchdr PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_include_directories(libchdr PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../libretro-common/include" + ) target_link_libraries(libchdr PRIVATE zlib lzma) diff --git a/dep/libchdr/include/libchdr/chd.h b/dep/libchdr/include/libchdr/chd.h index a37edc3f..ae976980 100644 --- a/dep/libchdr/include/libchdr/chd.h +++ b/dep/libchdr/include/libchdr/chd.h @@ -49,6 +49,8 @@ extern "C" { #include #include +#include + /*************************************************************************** Compressed Hunks of Data header format. All numbers are stored in diff --git a/dep/libchdr/include/libchdr/coretypes.h b/dep/libchdr/include/libchdr/coretypes.h index 338a0f0a..6c71b55a 100644 --- a/dep/libchdr/include/libchdr/coretypes.h +++ b/dep/libchdr/include/libchdr/coretypes.h @@ -4,9 +4,7 @@ #include #include -#ifdef USE_LIBRETRO_VFS -#include -#endif +#include #define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0])) @@ -29,29 +27,29 @@ typedef int32_t INT32; typedef int16_t INT16; typedef int8_t INT8; -#define core_file FILE -#define core_fopen(file) fopen(file, "rb") +#define core_file RFILE +#define core_fopen(file) rfopen(file, "rb") +#define core_fseek rfseek +#define core_ftell rftell +#define core_fread(fc, buff, len) rfread(buff, 1, len, fc) +#define core_fclose rfclose -#if defined USE_LIBRETRO_VFS - #define core_fseek fseek - #define core_ftell ftell -#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__) - #define core_fseek _fseeki64 - #define core_ftell _ftelli64 -#elif defined(_LARGEFILE_SOURCE) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 - #define core_fseek fseeko64 - #define core_ftell ftello64 -#elif defined(__PS3__) && !defined(__PSL1GHT__) || defined(__SWITCH__) - #define core_fseek(x,y,z) fseek(x,(off_t)y,z) - #define core_ftell(x) (off_t)ftell(x) -#else - #define core_fseek fseeko - #define core_ftell ftello +#ifdef __cplusplus +extern "C" { #endif -#define core_fread(fc, buff, len) fread(buff, 1, len, fc) -#define core_fclose fclose -static UINT64 core_fsize(core_file *f) +RFILE* rfopen(const char *path, const char *mode); +extern int64_t rfseek(RFILE* stream, int64_t offset, int origin); +extern int64_t rftell(RFILE* stream); +extern int64_t rfread(void* buffer, + size_t elem_size, size_t elem_count, RFILE* stream); +extern int rfclose(RFILE* stream); + +#ifdef __cplusplus +} +#endif + +static INLINE UINT64 core_fsize(core_file *f) { UINT64 rv; UINT64 p = core_ftell(f); diff --git a/src/common/cd_image_chd.cpp b/src/common/cd_image_chd.cpp index c58f4c1a..05f8bcd9 100644 --- a/src/common/cd_image_chd.cpp +++ b/src/common/cd_image_chd.cpp @@ -59,7 +59,7 @@ private: bool ReadHunk(u32 hunk_index); - std::FILE* m_fp = nullptr; + RFILE* m_fp = nullptr; chd_file* m_chd = nullptr; u32 m_hunk_size = 0; u32 m_sectors_per_hunk = 0; @@ -77,12 +77,12 @@ CDImageCHD::~CDImageCHD() if (m_chd) chd_close(m_chd); if (m_fp) - std::fclose(m_fp); + rfclose(m_fp); } bool CDImageCHD::Open(const char* filename, Common::Error* error) { - m_fp = FileSystem::OpenCFile(filename, "rb"); + m_fp = FileSystem::OpenRFile(filename, "rb"); if (!m_fp) { Log_ErrorPrintf("Failed to open CHD '%s': errno %d", filename, errno); diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index de0ae8ca..fed24c3d 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -31,17 +31,17 @@ #include #include -int rferror(RFILE* stream) +extern "C" int rferror(RFILE* stream) { return filestream_error(stream); } -int rfeof(RFILE* stream) +extern "C" int rfeof(RFILE* stream) { return filestream_eof(stream); } -char *rfgets(char *buffer, int maxCount, RFILE* stream) +extern "C" char *rfgets(char *buffer, int maxCount, RFILE* stream) { if (!stream) return NULL; @@ -49,7 +49,7 @@ char *rfgets(char *buffer, int maxCount, RFILE* stream) return filestream_gets(stream, buffer, maxCount); } -int rfgetc(RFILE* stream) +extern "C" int rfgetc(RFILE* stream) { if (!stream) return EOF; @@ -57,7 +57,7 @@ int rfgetc(RFILE* stream) return filestream_getc(stream); } -RFILE* rfopen(const char *path, const char *mode) +extern "C" RFILE* rfopen(const char *path, const char *mode) { RFILE *output = NULL; unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ; @@ -98,7 +98,7 @@ RFILE* rfopen(const char *path, const char *mode) return output; } -int rfclose(RFILE* stream) +extern "C" int rfclose(RFILE* stream) { if (!stream) return EOF; @@ -106,7 +106,7 @@ int rfclose(RFILE* stream) return filestream_close(stream); } -int64_t rftell(RFILE* stream) +extern "C" int64_t rftell(RFILE* stream) { if (!stream) return -1; @@ -114,7 +114,7 @@ int64_t rftell(RFILE* stream) return filestream_tell(stream); } -int64_t rfread(void* buffer, +extern "C" int64_t rfread(void* buffer, size_t elem_size, size_t elem_count, RFILE* stream) { if (!stream || (elem_size == 0) || (elem_count == 0)) @@ -123,7 +123,7 @@ int64_t rfread(void* buffer, return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size); } -int64_t rfseek(RFILE* stream, int64_t offset, int origin) +extern "C" int64_t rfseek(RFILE* stream, int64_t offset, int origin) { int seek_position = -1; @@ -146,7 +146,7 @@ int64_t rfseek(RFILE* stream, int64_t offset, int origin) return filestream_seek(stream, offset, seek_position); } -int64_t rfwrite(void const* buffer, +extern "C" int64_t rfwrite(void const* buffer, size_t elem_size, size_t elem_count, RFILE* stream) { if (!stream || (elem_size == 0) || (elem_count == 0)) diff --git a/src/common/file_system.h b/src/common/file_system.h index 12c063f8..18bfaca0 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -117,6 +117,10 @@ std::optional> ReadBinaryFile(RFILE* fp); }; // namespace FileSystem +#ifdef __cplusplus +extern "C" { +#endif + char *rfgets(char *buffer, int maxCount, RFILE* stream); int rfeof(RFILE* stream); int rferror(RFILE* stream); @@ -129,3 +133,7 @@ int64_t rfwrite(void const* buffer, int64_t rfread(void* buffer, size_t elem_size, size_t elem_count, RFILE* stream); int rfgetc(RFILE* stream); + +#ifdef __cplusplus +} +#endif