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
98# define htobe16(_x) __builtin_bswap16(_x)
101# define htole16(_x) ((uint16_t)(_x))
104# define be16toh(_x) __builtin_bswap16(_x)
107# define le16toh(_x) ((uint16_t)(_x))
110# define htobe32(_x) __builtin_bswap32(_x)
113# define htole32(_x) ((uint32_t)(_x))
116# define be32toh(_x) __builtin_bswap32(_x)
119# define le32toh(_x) ((uint32_t)(_x))
122# define htobe64(_x) __builtin_bswap64(_x)
125# define htole64(_x) ((uint64_t)(_x))
128# define be64toh(_x) __builtin_bswap64(_x)
131# define le64toh(_x) ((uint64_t)(_x))
133#elif BYTE_ORDER == BIG_ENDIAN
135# define htole16(_x) __builtin_bswap16(_x)
138# define htobe16(_x) ((uint16_t)(_x))
141# define le16toh(_x) __builtin_bswap16(_x)
144# define be16toh(_x) ((uint16_t)(_x))
147# define htole32(_x) __builtin_bswap32(_x)
150# define htobe32(_x) ((uint32_t)(_x))
153# define le32toh(_x) __builtin_bswap32(_x)
156# define be32toh(_x) ((uint32_t)(_x))
159# define htole64(_x) __builtin_bswap64(_x)
162# define htobe64(_x) ((uint64_t)(_x))
165# define le64toh(_x) __builtin_bswap64(_x)
168# define be64toh(_x) ((uint64_t)(_x))
171# 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