From 5d5dfdc3dac8e8a040cee72872406be7cfae5fee Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 23 Jan 2016 13:36:58 -1000 Subject: [PATCH] OS X build fixes --- include/NOD/Util.hpp | 12 ++++++++++++ lib/DiscBase.cpp | 2 +- lib/DiscWii.cpp | 16 ++++++++-------- lib/FileIOFILE.cpp | 4 ++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/NOD/Util.hpp b/include/NOD/Util.hpp index 6942c67..bea0b05 100644 --- a/include/NOD/Util.hpp +++ b/include/NOD/Util.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #endif #include @@ -249,6 +250,17 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo return fp; } +static inline int FSeek(FILE* fp, int64_t offset, int whence) +{ +#if NOD_UCS2 + return _fseeki64(fp, offset, whence); +#elif __APPLE__ || __FreeBSD__ + return fseeko(fp, offset, whence); +#else + return fseeko64(fp, offset, whence); +#endif +} + } #endif // __NOD_UTIL_HPP__ diff --git a/lib/DiscBase.cpp b/lib/DiscBase.cpp index b5e1fa2..cd2572b 100644 --- a/lib/DiscBase.cpp +++ b/lib/DiscBase.cpp @@ -293,7 +293,7 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(const SystemChar* ++m_parent.m_progressIdx; while (xferSz < dolStat.st_size) { - size_t rdSz = fread(buf, 1, std::min(8192ul, dolStat.st_size - xferSz), fp); + size_t rdSz = fread(buf, 1, std::min(size_t(8192), size_t(dolStat.st_size - xferSz)), fp); if (!rdSz) break; ws->write(buf, rdSz); diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index 0c807ef..7ce4fce 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -541,21 +541,21 @@ public: uint8_t tkey[16]; { - fseeko64(fp, 0x1BF, SEEK_SET); + FSeek(fp, 0x1BF, SEEK_SET); if (fread(tkey, 1, 16, fp) != 16) LogModule.report(LogVisor::FatalError, _S("unable to read title key from %s"), partHeadIn); } uint8_t tkeyiv[16] = {}; { - fseeko64(fp, 0x1DC, SEEK_SET); + FSeek(fp, 0x1DC, SEEK_SET); if (fread(tkeyiv, 1, 8, fp) != 8) LogModule.report(LogVisor::FatalError, _S("unable to read title key IV from %s"), partHeadIn); } uint8_t ccIdx; { - fseeko64(fp, 0x1F1, SEEK_SET); + FSeek(fp, 0x1F1, SEEK_SET); if (fread(&ccIdx, 1, 1, fp) != 1) LogModule.report(LogVisor::FatalError, _S("unable to read common key index from %s"), partHeadIn); if (ccIdx > 1) @@ -564,7 +564,7 @@ public: uint32_t tmdSz; { - fseeko64(fp, 0x2A4, SEEK_SET); + FSeek(fp, 0x2A4, SEEK_SET); if (fread(&tmdSz, 1, 4, fp) != 4) LogModule.report(LogVisor::FatalError, _S("unable to read TMD size from %s"), partHeadIn); tmdSz = SBig(tmdSz); @@ -573,7 +573,7 @@ public: uint64_t h3Off; { uint32_t h3Ptr; - fseeko64(fp, 0x2B4, SEEK_SET); + FSeek(fp, 0x2B4, SEEK_SET); if (fread(&h3Ptr, 1, 4, fp) != 4) LogModule.report(LogVisor::FatalError, _S("unable to read H3 pointer from %s"), partHeadIn); h3Off = uint64_t(SBig(h3Ptr)) << 2; @@ -588,7 +588,7 @@ public: } std::unique_ptr tmdData(new uint8_t[tmdSz]); - fseeko64(fp, 0x2C0, SEEK_SET); + FSeek(fp, 0x2C0, SEEK_SET); if (fread(tmdData.get(), 1, tmdSz, fp) != tmdSz) LogModule.report(LogVisor::FatalError, _S("unable to read TMD from %s"), partHeadIn); @@ -597,10 +597,10 @@ public: { uint64_t remCopy = h3Off; uint8_t copyBuf[8192]; - fseeko64(fp, 0, SEEK_SET); + FSeek(fp, 0, SEEK_SET); while (remCopy) { - size_t rdBytes = fread(copyBuf, 1, std::min(8192ul, remCopy), fp); + size_t rdBytes = fread(copyBuf, 1, std::min(size_t(8192), size_t(remCopy)), fp); if (rdBytes) { ws->write(copyBuf, rdBytes); diff --git a/lib/FileIOFILE.cpp b/lib/FileIOFILE.cpp index ff10584..04d7f3c 100644 --- a/lib/FileIOFILE.cpp +++ b/lib/FileIOFILE.cpp @@ -66,7 +66,7 @@ public: #endif if (!fp) LogModule.report(LogVisor::Error, _S("unable to open '%s' for writing"), path.c_str()); - fseeko64(fp, offset, SEEK_SET); + FSeek(fp, offset, SEEK_SET); } ~WriteStream() { @@ -125,7 +125,7 @@ public: ReadStream(const SystemString& path, uint64_t offset) : ReadStream(path) { - fseeko64(fp, offset, SEEK_SET); + FSeek(fp, offset, SEEK_SET); } ~ReadStream() {fclose(fp);} uint64_t read(void* buf, uint64_t length)