diff --git a/include/compat/endian.h b/include/compat/endian.h index cd85f5c..6dfe0b0 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h @@ -48,4 +48,65 @@ #endif #endif +#if defined(__APPLE__) && !defined(HAVE_ENDIAN_H) +#include +#define betoh16(x) OSSwapBigToHostInt16((x)) +#define htobe16(x) OSSwapHostToBigInt16((x)) +#define betoh32(x) OSSwapBigToHostInt32((x)) +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define htobe64(x) OSSwapHostToBigInt64(x) +#define letoh64(x) OSSwapLittleToHostInt64(x) +#define betoh64(x) OSSwapBigToHostInt64(x) +#endif /* __APPLE__ && !HAVE_ENDIAN_H */ + +#if defined(_WIN32) && !defined(HAVE_ENDIAN_H) +#include +#define betoh16(x) ntohs((x)) +#define htobe16(x) htons((x)) +#define betoh32(x) ntohl((x)) +#define htobe32(x) ntohl((x)) +#define betoh64(x) ntohll((x)) +#define htobe64(x) ntohll((x)) +#endif /* _WIN32 && !HAVE_ENDIAN_H */ + +#ifdef __linux__ +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif /* __linux__ */ + +#if defined(__FreeBSD__) +#if !defined(HAVE_ENDIAN_H) +#include +#endif +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif + +#if defined(__NetBSD__) +#if !defined(betoh16) +#define betoh16 be16toh +#endif +#if !defined(betoh32) +#define betoh32 be32toh +#endif +#if !defined(betoh64) +#define betoh64 be64toh +#endif +#endif + #endif