1 #ifndef UAE_ENDIAN_H 2 #define UAE_ENDIAN_H 3 4 #ifdef HAVE_CONFIG_H 5 #include "config.h" 6 #endif 7 8 #include "uae/types.h" 9 10 #ifdef _WIN32 11 12 /* Use custom conversion routines for Windows */ 13 #ifdef WORDS_BIGENDIAN 14 #error big-endian windows not supported here 15 #endif 16 17 #ifndef be16toh be16toh_impl(uint16_t v)18static inline uint16_t be16toh_impl(uint16_t v) 19 { 20 return (v << 8) | (v >> 8); 21 } 22 #define be16toh be16toh_impl 23 #endif 24 25 #ifndef le16toh le16toh_impl(uint16_t v)26static inline uint16_t le16toh_impl(uint16_t v) 27 { 28 return v; 29 } 30 #define le16toh le16toh_impl 31 #endif 32 33 #ifndef le32toh le32toh_impl(uint32_t v)34static inline uint32_t le32toh_impl(uint32_t v) 35 { 36 return v; 37 } 38 #define le32toh le32toh_impl 39 #endif 40 41 #elif defined(HAVE_LIBKERN_OSBYTEORDER_H) 42 43 /* OS X lacks endian.h, but has something similar */ 44 #include <libkern/OSByteOrder.h> 45 #define htobe16(x) OSSwapHostToBigInt16(x) 46 #define htole16(x) OSSwapHostToLittleInt16(x) 47 #define be16toh(x) OSSwapBigToHostInt16(x) 48 #define le16toh(x) OSSwapLittleToHostInt16(x) 49 #define htobe32(x) OSSwapHostToBigInt32(x) 50 #define htole32(x) OSSwapHostToLittleInt32(x) 51 #define be32toh(x) OSSwapBigToHostInt32(x) 52 #define le32toh(x) OSSwapLittleToHostInt32(x) 53 #define htobe64(x) OSSwapHostToBigInt64(x) 54 #define htole64(x) OSSwapHostToLittleInt64(x) 55 #define be64toh(x) OSSwapBigToHostInt64(x) 56 #define le64toh(x) OSSwapLittleToHostInt64(x) 57 58 #elif defined(HAVE_ENDIAN_H) 59 60 /* Linux has endian.h */ 61 #include <endian.h> 62 63 #elif defined(HAVE_SYS_ENDIAN_H) 64 65 /* BSD's generally have sys/endian.h */ 66 #include <sys/endian.h> 67 68 #endif 69 70 #endif /* UAE_ENDIAN_H */ 71