1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Memory: Add LittleEndian16(), LittleEndian32() and LittleEndian64()

This commit is contained in:
Daiyuu Nobori 2022-02-22 19:37:29 +01:00 committed by Davide Beatrici
parent 1e604407af
commit 56aedd6817
2 changed files with 45 additions and 0 deletions

View File

@ -3373,6 +3373,48 @@ UINT64 Endian64(UINT64 src)
} }
} }
// Endian conversion 16bit
USHORT LittleEndian16(USHORT src)
{
int x = 0x01000000;
if (*((char *)&x))
{
return Swap16(src);
}
else
{
return src;
}
}
// Endian conversion 32bit
UINT LittleEndian32(UINT src)
{
int x = 0x01000000;
if (*((char *)&x))
{
return Swap32(src);
}
else
{
return src;
}
}
// Endian conversion 64bit
UINT64 LittleEndian64(UINT64 src)
{
int x = 0x01000000;
if (*((char *)&x))
{
return Swap64(src);
}
else
{
return src;
}
}
// 16bit swap // 16bit swap
USHORT Swap16(USHORT value) USHORT Swap16(USHORT value)
{ {

View File

@ -199,6 +199,9 @@ UINT64 Swap64(UINT64 value);
USHORT Endian16(USHORT src); USHORT Endian16(USHORT src);
UINT Endian32(UINT src); UINT Endian32(UINT src);
UINT64 Endian64(UINT64 src); UINT64 Endian64(UINT64 src);
USHORT LittleEndian16(USHORT src);
UINT LittleEndian32(UINT src);
UINT64 LittleEndian64(UINT64 src);
void EndianUnicode(wchar_t *str); void EndianUnicode(wchar_t *str);
BUF *NewBuf(); BUF *NewBuf();