36#define LITTLE_ENDIAN magic-number
41#define BIG_ENDIAN magic-number
46#define PDP_ENDIAN magic-number
56#define BYTE_ORDER <LITTLE_ENDIAN or BIG_ENDIAN>
60uint16_t
be16toh(uint16_t big_endian_16bits);
61uint16_t
le16toh(uint16_t little_endian_16bits);
65uint32_t
be32toh(uint32_t big_endian_32bits);
66uint32_t
le32toh(uint32_t little_endian_32bits);
70uint64_t
be64toh(uint64_t big_endian_64bits);
71uint64_t
le64toh(uint64_t little_endian_64bits);
78# define LITTLE_ENDIAN 1234
81# define BIG_ENDIAN 4321
84# define PDP_ENDIAN 3412
87# define BYTE_ORDER __BYTE_ORDER__
92#if (LITTLE_ENDIAN != 1234) || (BIG_ENDIAN != 4321) || (PDP_ENDIAN != 3412)
93# error "Mismatching magic numbers to refer to endianness"
96#if BYTE_ORDER == LITTLE_ENDIAN
97# define htobe16(_x) __builtin_bswap16(_x)
98# define htole16(_x) ((uint16_t)(_x))
99# define be16toh(_x) __builtin_bswap16(_x)
100# define le16toh(_x) ((uint16_t)(_x))
101# define htobe32(_x) __builtin_bswap32(_x)
102# define htole32(_x) ((uint32_t)(_x))
103# define be32toh(_x) __builtin_bswap32(_x)
104# define le32toh(_x) ((uint32_t)(_x))
105# define htobe64(_x) __builtin_bswap64(_x)
106# define htole64(_x) ((uint64_t)(_x))
107# define be64toh(_x) __builtin_bswap64(_x)
108# define le64toh(_x) ((uint64_t)(_x))
109#elif BYTE_ORDER == BIG_ENDIAN
110# define htole16(_x) __builtin_bswap16(_x)
111# define htobe16(_x) ((uint16_t)(_x))
112# define le16toh(_x) __builtin_bswap16(_x)
113# define be16toh(_x) ((uint16_t)(_x))
114# define htole32(_x) __builtin_bswap32(_x)
115# define htobe32(_x) ((uint32_t)(_x))
116# define le32toh(_x) __builtin_bswap32(_x)
117# define be32toh(_x) ((uint32_t)(_x))
118# define htole64(_x) __builtin_bswap64(_x)
119# define htobe64(_x) ((uint64_t)(_x))
120# define le64toh(_x) __builtin_bswap64(_x)
121# define be64toh(_x) ((uint64_t)(_x))
123# error "Byte order not supported"
uint16_t be16toh(uint16_t big_endian_16bits)
big endian to host, 16 bit
uint16_t htobe16(uint16_t host_16bits)
host to big endian, 16 bit
uint32_t le32toh(uint32_t little_endian_32bits)
little endian to host, 32 bit
uint32_t htobe32(uint32_t host_32bits)
host to big endian, 32 bit
uint16_t le16toh(uint16_t little_endian_16bits)
little endian to host, 16 bit
uint64_t htobe64(uint64_t host_64bits)
host to big endian, 64 bit
uint64_t be64toh(uint64_t big_endian_64bits)
big endian to host, 64 bit
uint32_t be32toh(uint32_t big_endian_32bits)
big endian to host, 32 bit
uint64_t htole64(uint64_t host_64bits)
host to little endian, 64 bit
uint32_t htole32(uint32_t host_32bits)
host to little endian, 32 bit
uint16_t htole16(uint16_t host_16bits)
host to little endian, 16 bit
uint64_t le64toh(uint64_t little_endian_64bits)
little endian to host, 64 bit