libwinpr-crt: add byteswap macros

This commit is contained in:
Marc-André Moreau 2014-03-06 12:48:48 -05:00
parent 95127d5632
commit 77e91aa762

View File

@ -32,6 +32,36 @@
#ifndef _WIN32
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
#define _byteswap_ushort(_val) __builtin_bswap16(_val)
#define _byteswap_ulong(_val) __builtin_bswap32(_val)
#define _byteswap_uint64(_val) __builtin_bswap64(_val)
#else
#define _byteswap_ushort(_val) (((_val) >> 8) | ((_val) << 8))
#define _byteswap_ulong(_val) (((_val) >> 24) | \
(((_val) & 0x00FF0000) >> 8) | \
(((_val) & 0x0000FF00) << 8) | \
((_val) << 24))
#define _byteswap_uint64(_val) (((_val) << 56) | \
(((_val) << 40) & 0xFF000000000000) | \
(((_val) << 24) & 0xFF0000000000) | \
(((_val) << 8) & 0xFF00000000) | \
(((_val) >> 8) & 0xFF000000) | \
(((_val) >> 24) & 0xFF0000) | \
(((_val) >> 40) & 0xFF00) | \
((_val) >> 56))
#endif
#endif
#ifndef _WIN32
#define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
#define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))