diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/compat/endian.h | 61 |
1 files changed, 61 insertions, 0 deletions
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 @@ | |||
| 48 | #endif | 48 | #endif |
| 49 | #endif | 49 | #endif |
| 50 | 50 | ||
| 51 | #if defined(__APPLE__) && !defined(HAVE_ENDIAN_H) | ||
| 52 | #include <libkern/OSByteOrder.h> | ||
| 53 | #define betoh16(x) OSSwapBigToHostInt16((x)) | ||
| 54 | #define htobe16(x) OSSwapHostToBigInt16((x)) | ||
| 55 | #define betoh32(x) OSSwapBigToHostInt32((x)) | ||
| 56 | #define htobe32(x) OSSwapHostToBigInt32(x) | ||
| 57 | #define htole64(x) OSSwapHostToLittleInt64(x) | ||
| 58 | #define htobe64(x) OSSwapHostToBigInt64(x) | ||
| 59 | #define letoh64(x) OSSwapLittleToHostInt64(x) | ||
| 60 | #define betoh64(x) OSSwapBigToHostInt64(x) | ||
| 61 | #endif /* __APPLE__ && !HAVE_ENDIAN_H */ | ||
| 62 | |||
| 63 | #if defined(_WIN32) && !defined(HAVE_ENDIAN_H) | ||
| 64 | #include <winsock2.h> | ||
| 65 | #define betoh16(x) ntohs((x)) | ||
| 66 | #define htobe16(x) htons((x)) | ||
| 67 | #define betoh32(x) ntohl((x)) | ||
| 68 | #define htobe32(x) ntohl((x)) | ||
| 69 | #define betoh64(x) ntohll((x)) | ||
| 70 | #define htobe64(x) ntohll((x)) | ||
| 71 | #endif /* _WIN32 && !HAVE_ENDIAN_H */ | ||
| 72 | |||
| 73 | #ifdef __linux__ | ||
| 74 | #if !defined(betoh16) | ||
| 75 | #define betoh16 be16toh | ||
| 76 | #endif | ||
| 77 | #if !defined(betoh32) | ||
| 78 | #define betoh32 be32toh | ||
| 79 | #endif | ||
| 80 | #if !defined(betoh64) | ||
| 81 | #define betoh64 be64toh | ||
| 82 | #endif | ||
| 83 | #endif /* __linux__ */ | ||
| 84 | |||
| 85 | #if defined(__FreeBSD__) | ||
| 86 | #if !defined(HAVE_ENDIAN_H) | ||
| 87 | #include <sys/endian.h> | ||
| 88 | #endif | ||
| 89 | #if !defined(betoh16) | ||
| 90 | #define betoh16 be16toh | ||
| 91 | #endif | ||
| 92 | #if !defined(betoh32) | ||
| 93 | #define betoh32 be32toh | ||
| 94 | #endif | ||
| 95 | #if !defined(betoh64) | ||
| 96 | #define betoh64 be64toh | ||
| 97 | #endif | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #if defined(__NetBSD__) | ||
| 101 | #if !defined(betoh16) | ||
| 102 | #define betoh16 be16toh | ||
| 103 | #endif | ||
| 104 | #if !defined(betoh32) | ||
| 105 | #define betoh32 be32toh | ||
| 106 | #endif | ||
| 107 | #if !defined(betoh64) | ||
| 108 | #define betoh64 be64toh | ||
| 109 | #endif | ||
| 110 | #endif | ||
| 111 | |||
| 51 | #endif | 112 | #endif |
