mirror of https://github.com/AxioDL/nod.git
Add max-size check conditional
This commit is contained in:
parent
26af179ee8
commit
4adfa71c2f
|
@ -68,9 +68,12 @@ public:
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
uint64_t write(const void* buf, uint64_t length)
|
uint64_t write(const void* buf, uint64_t length)
|
||||||
|
{
|
||||||
|
if (m_maxWriteSize >= 0)
|
||||||
{
|
{
|
||||||
if (FTell(fp) + length > m_maxWriteSize)
|
if (FTell(fp) + length > m_maxWriteSize)
|
||||||
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
|
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
|
||||||
|
}
|
||||||
return fwrite(buf, 1, length, fp);
|
return fwrite(buf, 1, length, fp);
|
||||||
}
|
}
|
||||||
uint64_t copyFromDisc(IPartReadStream& discio, uint64_t length)
|
uint64_t copyFromDisc(IPartReadStream& discio, uint64_t length)
|
||||||
|
|
|
@ -71,12 +71,15 @@ public:
|
||||||
CloseHandle(fp);
|
CloseHandle(fp);
|
||||||
}
|
}
|
||||||
uint64_t write(const void* buf, uint64_t length)
|
uint64_t write(const void* buf, uint64_t length)
|
||||||
|
{
|
||||||
|
if (m_maxWriteSize >= 0)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER li = {};
|
LARGE_INTEGER li = {};
|
||||||
LARGE_INTEGER res;
|
LARGE_INTEGER res;
|
||||||
SetFilePointerEx(fp, li, &res, FILE_CURRENT);
|
SetFilePointerEx(fp, li, &res, FILE_CURRENT);
|
||||||
if (res.QuadPart + int64_t(length) > m_maxWriteSize)
|
if (res.QuadPart + int64_t(length) > m_maxWriteSize)
|
||||||
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
|
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
|
||||||
|
}
|
||||||
|
|
||||||
DWORD ret = 0;
|
DWORD ret = 0;
|
||||||
WriteFile(fp, buf, length, &ret, nullptr);
|
WriteFile(fp, buf, length, &ret, nullptr);
|
||||||
|
|
Loading…
Reference in New Issue