OS X build fixes

This commit is contained in:
Jack Andersen 2016-01-23 13:36:58 -10:00
parent dc4dda0d5f
commit 5d5dfdc3da
4 changed files with 23 additions and 11 deletions

View File

@ -15,6 +15,7 @@
#include <ctype.h>
#include <sys/file.h>
#include <unistd.h>
#include <errno.h>
#endif
#include <sys/stat.h>
@ -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__

View File

@ -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);

View File

@ -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<uint8_t[]> 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);

View File

@ -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)