DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/byteorder.h
00001 
00002 /* MinGW implements some MSVC idioms, so always test for MinGW first. */
00003 #if defined(__MINGW32__)
00004 
00005 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
00006 
00007 #  define htobe16(x) htons(x)
00008 #  define htole16(x) (x)
00009 #  define be16toh(x) ntohs(x)
00010 #  define le16toh(x) (x)
00011 
00012 #  define htobe32(x) htonl(x)
00013 #  define htole32(x) (x)
00014 #  define be32toh(x) ntohl(x)
00015 #  define le32toh(x) (x)
00016 
00017 #  define htobe64(x) htonll(x)
00018 #  define htole64(x) (x)
00019 #  define be64toh(x) ntohll(x)
00020 #  define le64toh(x) (x)
00021 
00022 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
00023 
00024 #  define htobe16(x) (x)
00025 #  define htole16(x) __builtin_bswap16(x)
00026 #  define be16toh(x) (x)
00027 #  define le16toh(x) __builtin_bswap16(x)
00028 
00029 #  define htobe32(x) (x)
00030 #  define htole32(x) __builtin_bswap32(x)
00031 #  define be32toh(x) (x)
00032 #  define le32toh(x) __builtin_bswap32(x)
00033 
00034 #  define htobe64(x) (x)
00035 #  define htole64(x) __builtin_bswap64(x)
00036 #  define be64toh(x) (x)
00037 #  define le64toh(x) __builtin_bswap64(x)
00038 
00039 # else
00040 #  error Unexpected __BYTE_ORDER__
00041 
00042 # endif /* __MINGW__ __BYTE_ORDER__ */
00043 
00044 #elif defined(_MSC_VER)
00045 
00046 # if BYTE_ORDER == LITTLE_ENDIAN
00047 
00048 # define htobe16(x) htons(x)
00049 # define htole16(x) (x)
00050 # define be16toh(x) ntohs(x)
00051 # define le16toh(x) (x)
00052 
00053 # define htobe32(x) htonl(x)
00054 # define htole32(x) (x)
00055 # define be32toh(x) ntohl(x)
00056 # define le32toh(x) (x)
00057 
00058 # define htobe64(x) htonll(x)
00059 # define htole64(x) (x)
00060 # define be64toh(x) ntohll(x)
00061 # define le64toh(x) (x)
00062 
00063 # elif BYTE_ORDER == BIG_ENDIAN
00064 
00065 # define htobe16(x) (x)
00066 # define htole16(x) __builtin_bswap16(x)
00067 # define be16toh(x) (x)
00068 # define le16toh(x) __builtin_bswap16(x)
00069 
00070 # define htobe32(x) (x)
00071 # define htole32(x) __builtin_bswap32(x)
00072 # define be32toh(x) (x)
00073 # define le32toh(x) __builtin_bswap32(x)
00074 
00075 # define htobe64(x) (x)
00076 # define htole64(x) __builtin_bswap64(x)
00077 # define be64toh(x) (x)
00078 # define le64toh(x) __builtin_bswap64(x)
00079 
00080 # else
00081 # error Unexpected BYTE_ORDER.
00082 
00083 # endif /* _MSC_VER BYTE_ORDER */
00084 
00085 #elif defined(__APPLE__)
00086  /* This is a simple compatibility shim to convert
00087  * BSD/Linux endian macros to the Mac OS X equivalents. */
00088 #include <libkern/OSByteOrder.h>
00089 #define htobe16(x) OSSwapHostToBigInt16(x)
00090 #define htole16(x) OSSwapHostToLittleInt16(x)
00091 #define be16toh(x) OSSwapBigToHostInt16(x)
00092 #define le16toh(x) OSSwapLittleToHostInt16(x)
00093 
00094 #define htobe32(x) OSSwapHostToBigInt32(x)
00095 #define htole32(x) OSSwapHostToLittleInt32(x)
00096 #define be32toh(x) OSSwapBigToHostInt32(x)
00097 #define le32toh(x) OSSwapLittleToHostInt32(x)
00098 
00099 #define htobe64(x) OSSwapHostToBigInt64(x)
00100 #define htole64(x) OSSwapHostToLittleInt64(x)
00101 #define be64toh(x) OSSwapBigToHostInt64(x)
00102 #define le64toh(x) OSSwapLittleToHostInt64(x)
00103 
00104 #elif defined(__linux__) || defined(__CYGWIN__)
00105 
00106 #include <endian.h>
00107 
00108 #elif defined(__OpenBSD__)
00109 
00110 #include <sys/endian.h>
00111 
00112 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
00113 
00114 #include <sys/endian.h>
00115 
00116 #define be16toh(x) betoh16(x)
00117 #define le16toh(x) letoh16(x)
00118 
00119 #define be32toh(x) betoh32(x)
00120 #define le32toh(x) letoh32(x)
00121 
00122 #define be64toh(x) betoh64(x)
00123 #define le64toh(x) letoh64(x)
00124 
00125 #endif
00126