5 #ifndef BITCOIN_COMPAT_ENDIAN_H
6 #define BITCOIN_COMPAT_ENDIAN_H
8 #if defined(HAVE_CONFIG_H)
16 #if defined(HAVE_ENDIAN_H)
18 #elif defined(HAVE_SYS_ENDIAN_H)
19 #include <sys/endian.h>
27 #define HAVE_DECL_HTOBE16 1
30 #define HAVE_DECL_HTOLE16 1
33 #define HAVE_DECL_BE16TOH 1
36 #define HAVE_DECL_LE16TOH 1
40 #define HAVE_DECL_HTOBE32 1
43 #define HAVE_DECL_HTOLE32 1
46 #define HAVE_DECL_BE32TOH 1
49 #define HAVE_DECL_LE32TOH 1
53 #define HAVE_DECL_HTOBE64 1
56 #define HAVE_DECL_HTOLE64 1
59 #define HAVE_DECL_BE64TOH 1
62 #define HAVE_DECL_LE64TOH 1
65 #endif // HAVE_CONFIG_H
67 #if defined(WORDS_BIGENDIAN)
69 #if HAVE_DECL_HTOBE16 == 0
70 inline uint16_t
htobe16(uint16_t host_16bits)
74 #endif // HAVE_DECL_HTOBE16
76 #if HAVE_DECL_HTOLE16 == 0
77 inline uint16_t
htole16(uint16_t host_16bits)
81 #endif // HAVE_DECL_HTOLE16
83 #if HAVE_DECL_BE16TOH == 0
84 inline uint16_t
be16toh(uint16_t big_endian_16bits)
86 return big_endian_16bits;
88 #endif // HAVE_DECL_BE16TOH
90 #if HAVE_DECL_LE16TOH == 0
91 inline uint16_t
le16toh(uint16_t little_endian_16bits)
93 return bswap_16(little_endian_16bits);
95 #endif // HAVE_DECL_LE16TOH
97 #if HAVE_DECL_HTOBE32 == 0
98 inline uint32_t
htobe32(uint32_t host_32bits)
102 #endif // HAVE_DECL_HTOBE32
104 #if HAVE_DECL_HTOLE32 == 0
105 inline uint32_t
htole32(uint32_t host_32bits)
109 #endif // HAVE_DECL_HTOLE32
111 #if HAVE_DECL_BE32TOH == 0
112 inline uint32_t
be32toh(uint32_t big_endian_32bits)
114 return big_endian_32bits;
116 #endif // HAVE_DECL_BE32TOH
118 #if HAVE_DECL_LE32TOH == 0
119 inline uint32_t
le32toh(uint32_t little_endian_32bits)
121 return bswap_32(little_endian_32bits);
123 #endif // HAVE_DECL_LE32TOH
125 #if HAVE_DECL_HTOBE64 == 0
126 inline uint64_t
htobe64(uint64_t host_64bits)
130 #endif // HAVE_DECL_HTOBE64
132 #if HAVE_DECL_HTOLE64 == 0
133 inline uint64_t
htole64(uint64_t host_64bits)
137 #endif // HAVE_DECL_HTOLE64
139 #if HAVE_DECL_BE64TOH == 0
140 inline uint64_t
be64toh(uint64_t big_endian_64bits)
142 return big_endian_64bits;
144 #endif // HAVE_DECL_BE64TOH
146 #if HAVE_DECL_LE64TOH == 0
147 inline uint64_t
le64toh(uint64_t little_endian_64bits)
149 return bswap_64(little_endian_64bits);
151 #endif // HAVE_DECL_LE64TOH
153 #else // WORDS_BIGENDIAN
155 #if HAVE_DECL_HTOBE16 == 0
160 #endif // HAVE_DECL_HTOBE16
162 #if HAVE_DECL_HTOLE16 == 0
167 #endif // HAVE_DECL_HTOLE16
169 #if HAVE_DECL_BE16TOH == 0
170 inline uint16_t
be16toh(uint16_t big_endian_16bits)
174 #endif // HAVE_DECL_BE16TOH
176 #if HAVE_DECL_LE16TOH == 0
177 inline uint16_t
le16toh(uint16_t little_endian_16bits)
179 return little_endian_16bits;
181 #endif // HAVE_DECL_LE16TOH
183 #if HAVE_DECL_HTOBE32 == 0
188 #endif // HAVE_DECL_HTOBE32
190 #if HAVE_DECL_HTOLE32 == 0
195 #endif // HAVE_DECL_HTOLE32
197 #if HAVE_DECL_BE32TOH == 0
198 inline uint32_t
be32toh(uint32_t big_endian_32bits)
202 #endif // HAVE_DECL_BE32TOH
204 #if HAVE_DECL_LE32TOH == 0
205 inline uint32_t
le32toh(uint32_t little_endian_32bits)
207 return little_endian_32bits;
209 #endif // HAVE_DECL_LE32TOH
211 #if HAVE_DECL_HTOBE64 == 0
216 #endif // HAVE_DECL_HTOBE64
218 #if HAVE_DECL_HTOLE64 == 0
223 #endif // HAVE_DECL_HTOLE64
225 #if HAVE_DECL_BE64TOH == 0
226 inline uint64_t
be64toh(uint64_t big_endian_64bits)
230 #endif // HAVE_DECL_BE64TOH
232 #if HAVE_DECL_LE64TOH == 0
233 inline uint64_t
le64toh(uint64_t little_endian_64bits)
235 return little_endian_64bits;
237 #endif // HAVE_DECL_LE64TOH
239 #endif // WORDS_BIGENDIAN
241 #endif // BITCOIN_COMPAT_ENDIAN_H