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