diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index ada31b5fe..d39c9e5a9 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -500,6 +500,31 @@ std::FILE* OpenCFile(const char* filename, const char* mode) #endif } +int FSeek64(std::FILE* fp, s64 offset, int whence) +{ +#ifdef _WIN32 + return _fseeki64(fp, offset, whence); +#else + // Prevent truncation on platforms which don't have a 64-bit off_t (Android 32-bit). + if constexpr (sizeof(off_t) != sizeof(s64)) + { + if (offset < std::numeric_limits::min() || offset > std::numeric_limits::max()) + return -1; + } + + return fseeko(fp, static_cast(offset), whence); +#endif +} + +s64 FTell64(std::FILE* fp) +{ +#ifdef _WIN32 + return static_cast(_ftelli64(fp)); +#else + return static_cast(ftello(fp)); +#endif +} + std::optional> ReadBinaryFile(const char* filename) { ManagedCFilePtr fp = OpenManagedCFile(filename, "rb"); diff --git a/src/common/file_system.h b/src/common/file_system.h index a1843d5a2..028f08740 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -183,6 +183,8 @@ std::unique_ptr OpenFile(const char* FileName, u32 Flags); using ManagedCFilePtr = std::unique_ptr; ManagedCFilePtr OpenManagedCFile(const char* filename, const char* mode); std::FILE* OpenCFile(const char* filename, const char* mode); +int FSeek64(std::FILE* fp, s64 offset, int whence); +s64 FTell64(std::FILE* fp); std::optional> ReadBinaryFile(const char* filename); std::optional> ReadBinaryFile(std::FILE* fp);