mirror of
https://github.com/libAthena/athena.git
synced 2025-07-04 12:16:06 +00:00
Linux build fixes from previous commit
This commit is contained in:
parent
304135f38a
commit
4f3531dd1f
@ -8,14 +8,14 @@
|
||||
#endif
|
||||
|
||||
namespace athena::io {
|
||||
FileReader::FileReader(std::string_view filename, atInt32 cacheSize, bool globalErr)
|
||||
FileReader::FileReader(std::string_view filename, int32_t cacheSize, bool globalErr)
|
||||
: m_fileHandle(nullptr), m_cacheData(nullptr), m_offset(0), m_globalErr(globalErr) {
|
||||
m_filename = filename;
|
||||
open();
|
||||
setCacheSize(cacheSize);
|
||||
}
|
||||
|
||||
FileReader::FileReader(std::wstring_view filename, atInt32 cacheSize, bool globalErr)
|
||||
FileReader::FileReader(std::wstring_view filename, int32_t cacheSize, bool globalErr)
|
||||
: m_fileHandle(nullptr), m_cacheData(nullptr), m_offset(0), m_globalErr(globalErr) {
|
||||
m_filename = utility::wideToUtf8(filename);
|
||||
open();
|
||||
@ -57,7 +57,7 @@ void FileReader::close() {
|
||||
return;
|
||||
}
|
||||
|
||||
void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||
void FileReader::seek(int64_t pos, SeekOrigin origin) {
|
||||
if (!isOpen())
|
||||
return;
|
||||
|
||||
@ -82,10 +82,10 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||
}
|
||||
|
||||
size_t block = m_offset / m_blockSize;
|
||||
if (atInt32(block) != m_curBlock) {
|
||||
if (int32_t(block) != m_curBlock) {
|
||||
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
||||
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
||||
m_curBlock = atInt32(block);
|
||||
m_curBlock = int32_t(block);
|
||||
}
|
||||
} else if (fseeko64(m_fileHandle, pos, int(origin)) != 0) {
|
||||
if (m_globalErr)
|
||||
@ -94,7 +94,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||
}
|
||||
}
|
||||
|
||||
atUint64 FileReader::position() const {
|
||||
uint64_t FileReader::position() const {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open");
|
||||
@ -104,10 +104,10 @@ atUint64 FileReader::position() const {
|
||||
if (m_blockSize > 0)
|
||||
return m_offset;
|
||||
else
|
||||
return atUint64(ftello64(m_fileHandle));
|
||||
return uint64_t(ftello64(m_fileHandle));
|
||||
}
|
||||
|
||||
atUint64 FileReader::length() const {
|
||||
uint64_t FileReader::length() const {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open");
|
||||
@ -117,7 +117,7 @@ atUint64 FileReader::length() const {
|
||||
return m_fileSize;
|
||||
}
|
||||
|
||||
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
||||
uint64_t FileReader::readUBytesToBuf(void* buf, uint64_t len) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open for reading");
|
||||
@ -134,20 +134,20 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
||||
len = m_fileSize - m_offset;
|
||||
|
||||
size_t block = m_offset / m_blockSize;
|
||||
atUint64 cacheOffset = m_offset % m_blockSize;
|
||||
atUint64 cacheSize;
|
||||
atUint64 rem = len;
|
||||
atUint8* dst = (atUint8*)buf;
|
||||
uint64_t cacheOffset = m_offset % m_blockSize;
|
||||
uint64_t cacheSize;
|
||||
uint64_t rem = len;
|
||||
uint8_t* dst = (uint8_t*)buf;
|
||||
|
||||
while (rem) {
|
||||
if (atInt32(block) != m_curBlock) {
|
||||
if (int32_t(block) != m_curBlock) {
|
||||
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
|
||||
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
|
||||
m_curBlock = atInt32(block);
|
||||
m_curBlock = int32_t(block);
|
||||
}
|
||||
|
||||
cacheSize = rem;
|
||||
if (atInt32(cacheSize + cacheOffset) > m_blockSize)
|
||||
if (int32_t(cacheSize + cacheOffset) > m_blockSize)
|
||||
cacheSize = m_blockSize - cacheOffset;
|
||||
|
||||
memmove(dst, m_cacheData.get() + cacheOffset, cacheSize);
|
||||
@ -157,20 +157,20 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
||||
++block;
|
||||
}
|
||||
m_offset += len;
|
||||
return atUint64(dst - reinterpret_cast<atUint8*>(buf));
|
||||
return uint64_t(dst - reinterpret_cast<uint8_t*>(buf));
|
||||
}
|
||||
}
|
||||
|
||||
void FileReader::setCacheSize(const atInt32 blockSize) {
|
||||
void FileReader::setCacheSize(const int32_t blockSize) {
|
||||
m_blockSize = blockSize;
|
||||
|
||||
atInt32 len = atInt32(length());
|
||||
int32_t len = int32_t(length());
|
||||
if (m_blockSize > len)
|
||||
m_blockSize = len;
|
||||
|
||||
m_curBlock = -1;
|
||||
if (m_blockSize > 0)
|
||||
m_cacheData.reset(new atUint8[m_blockSize]);
|
||||
m_cacheData.reset(new uint8_t[m_blockSize]);
|
||||
}
|
||||
|
||||
} // namespace athena::io
|
||||
|
@ -79,7 +79,7 @@ void FileWriter::close() {
|
||||
rename(tmpFilename.c_str(), m_filename.c_str());
|
||||
}
|
||||
|
||||
void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
||||
void FileWriter::seek(int64_t pos, SeekOrigin origin) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to seek in file, not open");
|
||||
@ -94,11 +94,11 @@ void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
||||
}
|
||||
}
|
||||
|
||||
atUint64 FileWriter::position() const { return atUint64(ftello64(m_fileHandle)); }
|
||||
uint64_t FileWriter::position() const { return uint64_t(ftello64(m_fileHandle)); }
|
||||
|
||||
atUint64 FileWriter::length() const { return utility::fileSize(m_filename); }
|
||||
uint64_t FileWriter::length() const { return utility::fileSize(m_filename); }
|
||||
|
||||
void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
|
||||
void FileWriter::writeUBytes(const uint8_t* data, uint64_t len) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open for writing");
|
||||
|
Loading…
x
Reference in New Issue
Block a user