mirror of https://github.com/libAthena/athena.git
Windows build fixes
This commit is contained in:
parent
0ada695c7a
commit
ffbd1a0bcd
|
@ -1 +1 @@
|
||||||
Subproject commit 6bcc3fd21694b5634cc006915bd049cf460a9a8d
|
Subproject commit 25ff2efc0aeab3ce886fb6be11a1878f3497ec4c
|
|
@ -19,20 +19,26 @@ constexpr bool isSystemBigEndian() { return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN
|
||||||
constexpr ::athena::Endian SystemEndian = isSystemBigEndian() ? Big : Little;
|
constexpr ::athena::Endian SystemEndian = isSystemBigEndian() ? Big : Little;
|
||||||
constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? Little : Big;
|
constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? Little : Big;
|
||||||
|
|
||||||
constexpr atInt16 swap16(atInt16 val) {
|
#if _MSC_VER
|
||||||
|
#define BSWAP_CONSTEXPR inline
|
||||||
|
#else
|
||||||
|
#define BSWAP_CONSTEXPR constexpr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BSWAP_CONSTEXPR atInt16 swap16(atInt16 val) {
|
||||||
#if __GNUC__
|
#if __GNUC__
|
||||||
return __builtin_bswap16(val);
|
return __builtin_bswap16(val);
|
||||||
#elif _WIN32
|
#elif _MSC_VER
|
||||||
return _byteswap_ushort(val);
|
return _byteswap_ushort(val);
|
||||||
#else
|
#else
|
||||||
return (val = (val << 8) | ((val >> 8) & 0xFF));
|
return (val = (val << 8) | ((val >> 8) & 0xFF));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
constexpr atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
|
BSWAP_CONSTEXPR atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
|
||||||
constexpr atInt32 swap32(atInt32 val) {
|
BSWAP_CONSTEXPR atInt32 swap32(atInt32 val) {
|
||||||
#if __GNUC__
|
#if __GNUC__
|
||||||
return __builtin_bswap32(val);
|
return __builtin_bswap32(val);
|
||||||
#elif _WIN32
|
#elif _MSC_VER
|
||||||
return _byteswap_ulong(val);
|
return _byteswap_ulong(val);
|
||||||
#else
|
#else
|
||||||
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
|
val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
|
||||||
|
@ -40,11 +46,11 @@ constexpr atInt32 swap32(atInt32 val) {
|
||||||
return val;
|
return val;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
constexpr atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
|
BSWAP_CONSTEXPR atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
|
||||||
constexpr atInt64 swap64(atInt64 val) {
|
BSWAP_CONSTEXPR atInt64 swap64(atInt64 val) {
|
||||||
#if __GNUC__
|
#if __GNUC__
|
||||||
return __builtin_bswap64(val);
|
return __builtin_bswap64(val);
|
||||||
#elif _WIN32
|
#elif _MSC_VER
|
||||||
return _byteswap_uint64(val);
|
return _byteswap_uint64(val);
|
||||||
#else
|
#else
|
||||||
return (val = ((atInt64)(
|
return (val = ((atInt64)(
|
||||||
|
@ -54,89 +60,89 @@ constexpr atInt64 swap64(atInt64 val) {
|
||||||
(((atInt64)(val)&0x000000000000FF00ULL) << 40) | (((atInt64)(val)&0x00000000000000FFULL) << 56))));
|
(((atInt64)(val)&0x000000000000FF00ULL) << 40) | (((atInt64)(val)&0x00000000000000FFULL) << 56))));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
constexpr atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
|
BSWAP_CONSTEXPR atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
|
||||||
constexpr float swapFloat(float val) {
|
BSWAP_CONSTEXPR float swapFloat(float val) {
|
||||||
union { float f; atInt32 i; } uval1 = {val};
|
union { float f; atInt32 i; } uval1 = {val};
|
||||||
union { atInt32 i; float f; } uval2 = {swap32(uval1.i)};
|
union { atInt32 i; float f; } uval2 = {swap32(uval1.i)};
|
||||||
return uval2.f;
|
return uval2.f;
|
||||||
}
|
}
|
||||||
constexpr double swapDouble(double val) {
|
BSWAP_CONSTEXPR double swapDouble(double val) {
|
||||||
union { double f; atInt64 i; } uval1 = {val};
|
union { double f; atInt64 i; } uval1 = {val};
|
||||||
union { atInt64 i; double f; } uval2 = {swap64(uval1.i)};
|
union { atInt64 i; double f; } uval2 = {swap64(uval1.i)};
|
||||||
return uval2.f;
|
return uval2.f;
|
||||||
}
|
}
|
||||||
constexpr atInt16 LittleInt16(atInt16& val) {
|
BSWAP_CONSTEXPR atInt16 LittleInt16(atInt16& val) {
|
||||||
if constexpr (athena::utility::isSystemBigEndian())
|
if constexpr (athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap16(val);
|
val = athena::utility::swap16(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint16 LittleUint16(atUint16& val) {
|
BSWAP_CONSTEXPR atUint16 LittleUint16(atUint16& val) {
|
||||||
atInt16 ret = val;
|
atInt16 ret = val;
|
||||||
LittleInt16(ret);
|
LittleInt16(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atInt16 BigInt16(atInt16& val) {
|
BSWAP_CONSTEXPR atInt16 BigInt16(atInt16& val) {
|
||||||
if constexpr (!athena::utility::isSystemBigEndian())
|
if constexpr (!athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap16(val);
|
val = athena::utility::swap16(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint16 BigUint16(atUint16& val) {
|
BSWAP_CONSTEXPR atUint16 BigUint16(atUint16& val) {
|
||||||
atInt16 ret = val;
|
atInt16 ret = val;
|
||||||
BigInt16(ret);
|
BigInt16(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atInt32 LittleInt32(atInt32& val) {
|
BSWAP_CONSTEXPR atInt32 LittleInt32(atInt32& val) {
|
||||||
if constexpr (athena::utility::isSystemBigEndian())
|
if constexpr (athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap32(val);
|
val = athena::utility::swap32(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint32 LittleUint32(atUint32& val) {
|
BSWAP_CONSTEXPR atUint32 LittleUint32(atUint32& val) {
|
||||||
atInt32 ret = val;
|
atInt32 ret = val;
|
||||||
LittleInt32(ret);
|
LittleInt32(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atInt32 BigInt32(atInt32& val) {
|
BSWAP_CONSTEXPR atInt32 BigInt32(atInt32& val) {
|
||||||
if constexpr (!athena::utility::isSystemBigEndian())
|
if constexpr (!athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap32(val);
|
val = athena::utility::swap32(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint32 BigUint32(atUint32& val) {
|
BSWAP_CONSTEXPR atUint32 BigUint32(atUint32& val) {
|
||||||
atInt32 ret = val;
|
atInt32 ret = val;
|
||||||
BigInt32(ret);
|
BigInt32(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atInt64 LittleInt64(atInt64& val) {
|
BSWAP_CONSTEXPR atInt64 LittleInt64(atInt64& val) {
|
||||||
if constexpr (athena::utility::isSystemBigEndian())
|
if constexpr (athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap64(val);
|
val = athena::utility::swap64(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint64 LittleUint64(atUint64& val) {
|
BSWAP_CONSTEXPR atUint64 LittleUint64(atUint64& val) {
|
||||||
atInt64 ret = val;
|
atInt64 ret = val;
|
||||||
LittleInt64(ret);
|
LittleInt64(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atInt64 BigInt64(atInt64& val) {
|
BSWAP_CONSTEXPR atInt64 BigInt64(atInt64& val) {
|
||||||
if constexpr (!athena::utility::isSystemBigEndian())
|
if constexpr (!athena::utility::isSystemBigEndian())
|
||||||
val = athena::utility::swap64(val);
|
val = athena::utility::swap64(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr atUint64 BigUint64(atUint64& val) {
|
BSWAP_CONSTEXPR atUint64 BigUint64(atUint64& val) {
|
||||||
atInt64 ret = val;
|
atInt64 ret = val;
|
||||||
BigInt64(ret);
|
BigInt64(ret);
|
||||||
val = ret;
|
val = ret;
|
||||||
|
@ -144,25 +150,25 @@ constexpr atUint64 BigUint64(atUint64& val) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr float LittleFloat(float val) {
|
BSWAP_CONSTEXPR float LittleFloat(float val) {
|
||||||
if constexpr (athena::utility::isSystemBigEndian())
|
if constexpr (athena::utility::isSystemBigEndian())
|
||||||
return athena::utility::swapFloat(val);
|
return athena::utility::swapFloat(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr float BigFloat(float val) {
|
BSWAP_CONSTEXPR float BigFloat(float val) {
|
||||||
if constexpr (!athena::utility::isSystemBigEndian())
|
if constexpr (!athena::utility::isSystemBigEndian())
|
||||||
return athena::utility::swapFloat(val);
|
return athena::utility::swapFloat(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr double LittleDouble(double val) {
|
BSWAP_CONSTEXPR double LittleDouble(double val) {
|
||||||
if constexpr (athena::utility::isSystemBigEndian())
|
if constexpr (athena::utility::isSystemBigEndian())
|
||||||
return athena::utility::swapDouble(val);
|
return athena::utility::swapDouble(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
constexpr double BigDouble(double val) {
|
BSWAP_CONSTEXPR double BigDouble(double val) {
|
||||||
if constexpr (!athena::utility::isSystemBigEndian())
|
if constexpr (!athena::utility::isSystemBigEndian())
|
||||||
return athena::utility::swapDouble(val);
|
return athena::utility::swapDouble(val);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ void FileReader::open() {
|
||||||
m_fileHandle = 0;
|
m_fileHandle = 0;
|
||||||
std::string _filename = filename();
|
std::string _filename = filename();
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("File not found '{}'", _filename);
|
atError(fmt("File not found '{}'"), _filename);
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ void FileReader::open() {
|
||||||
void FileReader::close() {
|
void FileReader::close() {
|
||||||
if (!m_fileHandle) {
|
if (!m_fileHandle) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Cannot close an unopened stream");
|
atError(fmt("Cannot close an unopened stream"));
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||||
if (m_offset > length()) {
|
if (m_offset > length()) {
|
||||||
oldOff = m_offset;
|
oldOff = m_offset;
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to seek in file");
|
atError(fmt("Unable to seek in file"));
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||||
li.QuadPart = pos;
|
li.QuadPart = pos;
|
||||||
if (!SetFilePointerEx(m_fileHandle, li, nullptr, DWORD(origin))) {
|
if (!SetFilePointerEx(m_fileHandle, li, nullptr, DWORD(origin))) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to seek in file");
|
atError(fmt("Unable to seek in file"));
|
||||||
setError();
|
setError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
||||||
atUint64 FileReader::position() const {
|
atUint64 FileReader::position() const {
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("File not open");
|
atError(fmt("File not open"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ atUint64 FileReader::position() const {
|
||||||
atUint64 FileReader::length() const {
|
atUint64 FileReader::length() const {
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("File not open");
|
atError(fmt("File not open"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ atUint64 FileReader::length() const {
|
||||||
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("File not open for reading");
|
atError(fmt("File not open for reading"));
|
||||||
setError();
|
setError();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ void FileWriter::open(bool overwrite) {
|
||||||
if (m_fileHandle == INVALID_HANDLE_VALUE) {
|
if (m_fileHandle == INVALID_HANDLE_VALUE) {
|
||||||
m_fileHandle = 0;
|
m_fileHandle = 0;
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to open file '{}'", filename());
|
atError(fmt("Unable to open file '{}'"), filename());
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ void FileWriter::open(bool overwrite) {
|
||||||
void FileWriter::close() {
|
void FileWriter::close() {
|
||||||
if (!m_fileHandle) {
|
if (!m_fileHandle) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Cannot close an unopened stream");
|
atError(fmt("Cannot close an unopened stream"));
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ void FileWriter::close() {
|
||||||
void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to seek in file, not open");
|
atError(fmt("Unable to seek in file, not open"));
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
||||||
li.QuadPart = pos;
|
li.QuadPart = pos;
|
||||||
if (!SetFilePointerEx(m_fileHandle, li, nullptr, DWORD(origin))) {
|
if (!SetFilePointerEx(m_fileHandle, li, nullptr, DWORD(origin))) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to seek in file");
|
atError(fmt("Unable to seek in file"));
|
||||||
setError();
|
setError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ atUint64 FileWriter::length() const { return utility::fileSize(m_filename); }
|
||||||
void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
|
void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("File not open for writing");
|
atError(fmt("File not open for writing"));
|
||||||
setError();
|
setError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
|
||||||
WriteFile(m_fileHandle, data, len, &ret, nullptr);
|
WriteFile(m_fileHandle, data, len, &ret, nullptr);
|
||||||
if (ret != len) {
|
if (ret != len) {
|
||||||
if (m_globalErr)
|
if (m_globalErr)
|
||||||
atError("Unable to write to stream");
|
atError(fmt("Unable to write to stream"));
|
||||||
setError();
|
setError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ Socket::EResult Socket::accept(Socket& remoteSocketOut, sockaddr_in& fromAddress
|
||||||
#else
|
#else
|
||||||
EResult res = LastWSAError();
|
EResult res = LastWSAError();
|
||||||
if (res == EResult::Error)
|
if (res == EResult::Error)
|
||||||
atError("Failed to accept incoming connection");
|
atError(fmt("Failed to accept incoming connection"));
|
||||||
#endif
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue