diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2020-12-27 16:51:03 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 19:35:32 +0100 |
commit | 02fcf3974ef7c37b6af57683d9c884d996495b68 (patch) | |
tree | 80908e73e72d6d03cb80021bc47964533cc89bc4 /AK | |
parent | 42323d769a54d6aeef209f42f64174db09083e22 (diff) | |
download | serenity-02fcf3974ef7c37b6af57683d9c884d996495b68.zip |
AK/Userland: Use AK/Endian.h for portable byte swapping in ntpquery
Create macros for the byte swap operations one would expect to be in
endian.h or byteswap.h in AK/Endian.h. It's likely a similar/different
change will be needed for BSDs, but there's no github action for those
added to the project yet.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Endian.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/AK/Endian.h b/AK/Endian.h index 1c6e91e1da..f8b0a5fdc2 100644 --- a/AK/Endian.h +++ b/AK/Endian.h @@ -29,6 +29,30 @@ #include <AK/Forward.h> #include <AK/Platform.h> +#if defined(AK_OS_MACOS) +# include <libkern/OSByteOrder.h> +# include <machine/endian.h> + +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htole16(x) OSSwapHostToLittleInt16(x) +# define be16toh(x) OSSwapBigToHostInt16(x) +# define le16toh(x) OSSwapLittleToHostInt16(x) + +# define htobe32(x) OSSwapHostToBigInt32(x) +# define htole32(x) OSSwapHostToLittleInt32(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +# define htobe64(x) OSSwapHostToBigInt64(x) +# define htole64(x) OSSwapHostToLittleInt64(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) + +# define __BIG_ENDIAN BIG_ENDIAN +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BYTE_ORDER BYTE_ORDER +#endif + namespace AK { template<typename T> |