5 #ifndef PIVX_COMPAT_ENDIAN_H
6 #define PIVX_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
67 #if defined(WORDS_BIGENDIAN)
69 #if HAVE_DECL_HTOBE16 == 0
70 inline uint16_t
htobe16(uint16_t host_16bits)
76 #if HAVE_DECL_HTOLE16 == 0
77 inline uint16_t
htole16(uint16_t host_16bits)
83 #if HAVE_DECL_BE16TOH == 0
84 inline uint16_t
be16toh(uint16_t big_endian_16bits)
86 return big_endian_16bits;
90 #if HAVE_DECL_LE16TOH == 0
91 inline uint16_t
le16toh(uint16_t little_endian_16bits)
93 return bswap_16(little_endian_16bits);
97 #if HAVE_DECL_HTOBE32 == 0
98 inline uint32_t
htobe32(uint32_t host_32bits)
104 #if HAVE_DECL_HTOLE32 == 0
105 inline uint32_t
htole32(uint32_t host_32bits)
111 #if HAVE_DECL_BE32TOH == 0
112 inline uint32_t
be32toh(uint32_t big_endian_32bits)
114 return big_endian_32bits;
118 #if HAVE_DECL_LE32TOH == 0
119 inline uint32_t
le32toh(uint32_t little_endian_32bits)
121 return bswap_32(little_endian_32bits);
125 #if HAVE_DECL_HTOBE64 == 0
126 inline uint64_t
htobe64(uint64_t host_64bits)
132 #if HAVE_DECL_HTOLE64 == 0
133 inline uint64_t
htole64(uint64_t host_64bits)
139 #if HAVE_DECL_BE64TOH == 0
140 inline uint64_t
be64toh(uint64_t big_endian_64bits)
142 return big_endian_64bits;
146 #if HAVE_DECL_LE64TOH == 0
147 inline uint64_t
le64toh(uint64_t little_endian_64bits)
149 return bswap_64(little_endian_64bits);
155 #if HAVE_DECL_HTOBE16 == 0
162 #if HAVE_DECL_HTOLE16 == 0
169 #if HAVE_DECL_BE16TOH == 0
170 inline uint16_t
be16toh(uint16_t big_endian_16bits)
176 #if HAVE_DECL_LE16TOH == 0
177 inline uint16_t
le16toh(uint16_t little_endian_16bits)
179 return little_endian_16bits;
183 #if HAVE_DECL_HTOBE32 == 0
190 #if HAVE_DECL_HTOLE32 == 0
197 #if HAVE_DECL_BE32TOH == 0
198 inline uint32_t
be32toh(uint32_t big_endian_32bits)
204 #if HAVE_DECL_LE32TOH == 0
205 inline uint32_t
le32toh(uint32_t little_endian_32bits)
207 return little_endian_32bits;
211 #if HAVE_DECL_HTOBE64 == 0
218 #if HAVE_DECL_HTOLE64 == 0
225 #if HAVE_DECL_BE64TOH == 0
226 inline uint64_t
be64toh(uint64_t big_endian_64bits)
232 #if HAVE_DECL_LE64TOH == 0
233 inline uint64_t
le64toh(uint64_t little_endian_64bits)
235 return little_endian_64bits;
uint16_t bswap_16(uint16_t x)
uint64_t bswap_64(uint64_t x)
uint32_t bswap_32(uint32_t x)
uint16_t be16toh(uint16_t big_endian_16bits)
uint16_t htobe16(uint16_t host_16bits)
uint32_t le32toh(uint32_t little_endian_32bits)
uint32_t htobe32(uint32_t host_32bits)
uint16_t le16toh(uint16_t little_endian_16bits)
uint64_t htobe64(uint64_t host_64bits)
uint64_t be64toh(uint64_t big_endian_64bits)
uint32_t be32toh(uint32_t big_endian_32bits)
uint64_t htole64(uint64_t host_64bits)
uint32_t htole32(uint32_t host_32bits)
uint16_t htole16(uint16_t host_16bits)
uint64_t le64toh(uint64_t little_endian_64bits)