diff options
author | Theo Buehler <tb@openbsd.org> | 2023-04-11 17:41:07 +0200 |
---|---|---|
committer | Theo Buehler <tb@openbsd.org> | 2023-04-11 17:41:07 +0200 |
commit | 54e8591976da9f5f2c12e948004b087d7473d4b0 (patch) | |
tree | 1aa37fcfa08bab7c53793837ee4867a15e03dd46 /include | |
parent | 462369e82a888bd3c2647d7d136511f4a0e955f4 (diff) | |
parent | be58e25d2c6220ec7d299560facb1cf057dfb76d (diff) | |
download | portable-54e8591976da9f5f2c12e948004b087d7473d4b0.tar.gz portable-54e8591976da9f5f2c12e948004b087d7473d4b0.tar.bz2 portable-54e8591976da9f5f2c12e948004b087d7473d4b0.zip |
Land #837
Diffstat (limited to 'include')
-rw-r--r-- | include/compat/endian.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/include/compat/endian.h b/include/compat/endian.h index cd85f5c..ca3465d 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h | |||
@@ -48,4 +48,74 @@ | |||
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 | |||
66 | #define betoh16(x) ntohs((x)) | ||
67 | #define htobe16(x) htons((x)) | ||
68 | #define betoh32(x) ntohl((x)) | ||
69 | #define htobe32(x) ntohl((x)) | ||
70 | #define betoh64(x) ntohll((x)) | ||
71 | |||
72 | #if !defined(ntohll) | ||
73 | #define ntohll(x) ((1==htonl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) | ||
74 | #endif | ||
75 | #if !defined(htonll) | ||
76 | #define htonll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) | ||
77 | #endif | ||
78 | |||
79 | #define htobe64(x) ntohll((x)) | ||
80 | #endif /* _WIN32 && !HAVE_ENDIAN_H */ | ||
81 | |||
82 | #ifdef __linux__ | ||
83 | #if !defined(betoh16) | ||
84 | #define betoh16 be16toh | ||
85 | #endif | ||
86 | #if !defined(betoh32) | ||
87 | #define betoh32 be32toh | ||
88 | #endif | ||
89 | #if !defined(betoh64) | ||
90 | #define betoh64 be64toh | ||
91 | #endif | ||
92 | #endif /* __linux__ */ | ||
93 | |||
94 | #if defined(__FreeBSD__) | ||
95 | #if !defined(HAVE_ENDIAN_H) | ||
96 | #include <sys/endian.h> | ||
97 | #endif | ||
98 | #if !defined(betoh16) | ||
99 | #define betoh16 be16toh | ||
100 | #endif | ||
101 | #if !defined(betoh32) | ||
102 | #define betoh32 be32toh | ||
103 | #endif | ||
104 | #if !defined(betoh64) | ||
105 | #define betoh64 be64toh | ||
106 | #endif | ||
107 | #endif | ||
108 | |||
109 | #if defined(__NetBSD__) | ||
110 | #if !defined(betoh16) | ||
111 | #define betoh16 be16toh | ||
112 | #endif | ||
113 | #if !defined(betoh32) | ||
114 | #define betoh32 be32toh | ||
115 | #endif | ||
116 | #if !defined(betoh64) | ||
117 | #define betoh64 be64toh | ||
118 | #endif | ||
119 | #endif | ||
120 | |||
51 | #endif | 121 | #endif |