5#ifndef BITCOIN_COMPAT_ENDIAN_H
6#define BITCOIN_COMPAT_ENDIAN_H
8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-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
70inline uint16_t
htobe16(uint16_t host_16bits) {
75#if HAVE_DECL_HTOLE16 == 0
76inline uint16_t
htole16(uint16_t host_16bits) {
81#if HAVE_DECL_BE16TOH == 0
82inline uint16_t
be16toh(uint16_t big_endian_16bits) {
83 return big_endian_16bits;
87#if HAVE_DECL_LE16TOH == 0
88inline uint16_t
le16toh(uint16_t little_endian_16bits) {
89 return bswap_16(little_endian_16bits);
93#if HAVE_DECL_HTOBE32 == 0
94inline uint32_t
htobe32(uint32_t host_32bits) {
99#if HAVE_DECL_HTOLE32 == 0
100inline uint32_t
htole32(uint32_t host_32bits) {
105#if HAVE_DECL_BE32TOH == 0
106inline uint32_t
be32toh(uint32_t big_endian_32bits) {
107 return big_endian_32bits;
111#if HAVE_DECL_LE32TOH == 0
112inline uint32_t
le32toh(uint32_t little_endian_32bits) {
113 return bswap_32(little_endian_32bits);
117#if HAVE_DECL_HTOBE64 == 0
118inline uint64_t
htobe64(uint64_t host_64bits) {
123#if HAVE_DECL_HTOLE64 == 0
124inline uint64_t
htole64(uint64_t host_64bits) {
129#if HAVE_DECL_BE64TOH == 0
130inline uint64_t
be64toh(uint64_t big_endian_64bits) {
131 return big_endian_64bits;
135#if HAVE_DECL_LE64TOH == 0
136inline uint64_t
le64toh(uint64_t little_endian_64bits) {
137 return bswap_64(little_endian_64bits);
143#if HAVE_DECL_HTOBE16 == 0
144inline uint16_t
htobe16(uint16_t host_16bits) {
149#if HAVE_DECL_HTOLE16 == 0
150inline uint16_t
htole16(uint16_t host_16bits) {
155#if HAVE_DECL_BE16TOH == 0
156inline uint16_t
be16toh(uint16_t big_endian_16bits) {
161#if HAVE_DECL_LE16TOH == 0
162inline uint16_t
le16toh(uint16_t little_endian_16bits) {
163 return little_endian_16bits;
167#if HAVE_DECL_HTOBE32 == 0
168inline uint32_t
htobe32(uint32_t host_32bits) {
173#if HAVE_DECL_HTOLE32 == 0
174inline uint32_t
htole32(uint32_t host_32bits) {
179#if HAVE_DECL_BE32TOH == 0
180inline uint32_t
be32toh(uint32_t big_endian_32bits) {
185#if HAVE_DECL_LE32TOH == 0
186inline uint32_t
le32toh(uint32_t little_endian_32bits) {
187 return little_endian_32bits;
191#if HAVE_DECL_HTOBE64 == 0
192inline uint64_t
htobe64(uint64_t host_64bits) {
197#if HAVE_DECL_HTOLE64 == 0
198inline uint64_t
htole64(uint64_t host_64bits) {
203#if HAVE_DECL_BE64TOH == 0
204inline uint64_t
be64toh(uint64_t big_endian_64bits) {
209#if HAVE_DECL_LE64TOH == 0
210inline uint64_t
le64toh(uint64_t little_endian_64bits) {
211 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)