32 #define LITTLE_ENDIAN magic-number
37 #define BIG_ENDIAN magic-number
42 #define PDP_ENDIAN magic-number
52 #define BYTE_ORDER <LITTLE_ENDIAN or BIG_ENDIAN>
56 uint16_t
be16toh(uint16_t big_endian_16bits);
57 uint16_t
le16toh(uint16_t little_endian_16bits);
61 uint32_t
be32toh(uint32_t big_endian_32bits);
62 uint32_t
le32toh(uint32_t little_endian_32bits);
66 uint64_t
be64toh(uint64_t big_endian_64bits);
67 uint64_t
le64toh(uint64_t little_endian_64bits);
74 # define LITTLE_ENDIAN 1234
77 # define BIG_ENDIAN 4321
80 # define PDP_ENDIAN 3412
83 # define BYTE_ORDER __BYTE_ORDER__
88 #if (LITTLE_ENDIAN != 1234) || (BIG_ENDIAN != 4321) || (PDP_ENDIAN != 3412)
89 # error "Mismatching magic numbers to refer to endianness"
92 #if BYTE_ORDER == LITTLE_ENDIAN
94 # define htobe16(_x) __builtin_bswap16(_x)
97 # define htole16(_x) ((uint16_t)(_x))
100 # define be16toh(_x) __builtin_bswap16(_x)
103 # define le16toh(_x) ((uint16_t)(_x))
106 # define htobe32(_x) __builtin_bswap32(_x)
109 # define htole32(_x) ((uint32_t)(_x))
112 # define be32toh(_x) __builtin_bswap32(_x)
115 # define le32toh(_x) ((uint32_t)(_x))
118 # define htobe64(_x) __builtin_bswap64(_x)
121 # define htole64(_x) ((uint64_t)(_x))
124 # define be64toh(_x) __builtin_bswap64(_x)
127 # define le64toh(_x) ((uint64_t)(_x))
129 #elif BYTE_ORDER == BIG_ENDIAN
131 # define htole16(_x) __builtin_bswap16(_x)
134 # define htobe16(_x) ((uint16_t)(_x))
137 # define le16toh(_x) __builtin_bswap16(_x)
140 # define be16toh(_x) ((uint16_t)(_x))
143 # define htole32(_x) __builtin_bswap32(_x)
146 # define htobe32(_x) ((uint32_t)(_x))
149 # define le32toh(_x) __builtin_bswap32(_x)
152 # define be32toh(_x) ((uint32_t)(_x))
155 # define htole64(_x) __builtin_bswap64(_x)
158 # define htobe64(_x) ((uint64_t)(_x))
161 # define le64toh(_x) __builtin_bswap64(_x)
164 # define be64toh(_x) ((uint64_t)(_x))
167 # 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