Go to the documentation of this file. 10 #ifndef CLUON_PORTABLEENDIAN_HPP 11 #define CLUON_PORTABLEENDIAN_HPP 14 #if defined(__linux__) || defined(__CYGWIN__) 16 #elif defined(__APPLE__) 17 #include <libkern/OSByteOrder.h> 18 #define htobe16(x) OSSwapHostToBigInt16(x) 19 #define htole16(x) OSSwapHostToLittleInt16(x) 20 #define be16toh(x) OSSwapBigToHostInt16(x) 21 #define le16toh(x) OSSwapLittleToHostInt16(x) 23 #define htobe32(x) OSSwapHostToBigInt32(x) 24 #define htole32(x) OSSwapHostToLittleInt32(x) 25 #define be32toh(x) OSSwapBigToHostInt32(x) 26 #define le32toh(x) OSSwapLittleToHostInt32(x) 28 #define htobe64(x) OSSwapHostToBigInt64(x) 29 #define htole64(x) OSSwapHostToLittleInt64(x) 30 #define be64toh(x) OSSwapBigToHostInt64(x) 31 #define le64toh(x) OSSwapLittleToHostInt64(x) 32 #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 33 #include <sys/endian.h> 34 #elif (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) 35 #if BYTE_ORDER == LITTLE_ENDIAN 38 #define htonll(x) ((1==htonl(1)) ? (x) : (((uint64_t)htonl((x) & 0xFFFFFFFFUL)) << 32) | htonl((uint32_t)((x) >> 32))) 41 #define ntohll(x) ((1==ntohl(1)) ? (x) : (((uint64_t)ntohl((x) & 0xFFFFFFFFUL)) << 32) | ntohl((uint32_t)((x) >> 32))) 44 #define htobe16(x) htons(x) 45 #define htole16(x) (x) 46 #define be16toh(x) ntohs(x) 47 #define le16toh(x) (x) 49 #define htobe32(x) htonl(x) 50 #define htole32(x) (x) 51 #define be32toh(x) ntohl(x) 52 #define le32toh(x) (x) 54 #define htobe64(x) htonll(x) 55 #define htole64(x) (x) 56 #define be64toh(x) ntohll(x) 57 #define le64toh(x) (x) 58 #elif BYTE_ORDER == BIG_ENDIAN 60 #define htobe16(x) (x) 61 #define htole16(x) __builtin_bswap16(x) 62 #define be16toh(x) (x) 63 #define le16toh(x) __builtin_bswap16(x) 65 #define htobe32(x) (x) 66 #define htole32(x) __builtin_bswap32(x) 67 #define be32toh(x) (x) 68 #define le32toh(x) __builtin_bswap32(x) 70 #define htobe64(x) (x) 71 #define htole64(x) __builtin_bswap64(x) 72 #define be64toh(x) (x) 73 #define le64toh(x) __builtin_bswap64(x) 75 #error byte order not supported 81 #warning platform not supported