|
65 | 65 |
|
66 | 66 | #elif defined(__WINDOWS__)
|
67 | 67 |
|
68 |
| -# include <winsock2.h> |
69 |
| -# ifdef __GNUC__ |
70 |
| -# include <sys/param.h> |
| 68 | + |
| 69 | +# if defined(_MSC_VER) && !defined(__clang__) |
| 70 | +# include <stdlib.h> |
| 71 | +# define B_SWAP_16(x) _byteswap_ushort(x) |
| 72 | +# define B_SWAP_32(x) _byteswap_ulong(x) |
| 73 | +# define B_SWAP_64(x) _byteswap_uint64(x) |
| 74 | +# else |
| 75 | +# define B_SWAP_16(x) __builtin_bswap16(x) |
| 76 | +# define B_SWAP_32(x) __builtin_bswap32(x) |
| 77 | +# define B_SWAP_64(x) __builtin_bswap64(x) |
| 78 | +# endif |
| 79 | + |
| 80 | +# if defined(__MINGW32__) || defined(HAVE_SYS_PARAM_H) |
| 81 | +# include <sys/param.h> |
| 82 | +# endif |
| 83 | + |
| 84 | +# ifndef BIG_ENDIAN |
| 85 | +# ifdef __BIG_ENDIAN |
| 86 | +# define BIG_ENDIAN __BIG_ENDIAN |
| 87 | +# elif defined(__ORDER_BIG_ENDIAN__) |
| 88 | +# define BIG_ENDIAN __ORDER_BIG_ENDIAN__ |
| 89 | +# else |
| 90 | +# define BIG_ENDIAN 4321 |
| 91 | +# endif |
| 92 | +# endif |
| 93 | + |
| 94 | +# ifndef LITTLE_ENDIAN |
| 95 | +# ifdef __LITTLE_ENDIAN |
| 96 | +# define LITTLE_ENDIAN __LITTLE_ENDIAN |
| 97 | +# elif defined(__ORDER_LITTLE_ENDIAN__) |
| 98 | +# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ |
| 99 | +# else |
| 100 | +# define LITTLE_ENDIAN 1234 |
| 101 | +# endif |
| 102 | +# endif |
| 103 | + |
| 104 | +# ifndef BYTE_ORDER |
| 105 | +# ifdef __BYTE_ORDER |
| 106 | +# define BYTE_ORDER __BYTE_ORDER |
| 107 | +# elif defined(__BYTE_ORDER__) |
| 108 | +# define BYTE_ORDER __BYTE_ORDER__ |
| 109 | +# else |
| 110 | + /* assume LE on Windows if nothing was defined */ |
| 111 | +# define BYTE_ORDER LITTLE_ENDIAN |
| 112 | +# endif |
71 | 113 | # endif
|
72 | 114 |
|
73 | 115 | # if BYTE_ORDER == LITTLE_ENDIAN
|
74 | 116 |
|
75 |
| -# define htobe16(x) htons(x) |
| 117 | +# define htobe16(x) B_SWAP_16(x) |
76 | 118 | # define htole16(x) (x)
|
77 |
| -# define be16toh(x) ntohs(x) |
| 119 | +# define be16toh(x) B_SWAP_16(x) |
78 | 120 | # define le16toh(x) (x)
|
79 |
| - |
80 |
| -# define htobe32(x) htonl(x) |
| 121 | + |
| 122 | +# define htobe32(x) B_SWAP_32(x) |
81 | 123 | # define htole32(x) (x)
|
82 |
| -# define be32toh(x) ntohl(x) |
| 124 | +# define be32toh(x) B_SWAP_32(x) |
83 | 125 | # define le32toh(x) (x)
|
84 |
| - |
85 |
| -# define htobe64(x) htonll(x) |
| 126 | + |
| 127 | +# define htobe64(x) B_SWAP_64(x) |
86 | 128 | # define htole64(x) (x)
|
87 |
| -# define be64toh(x) ntohll(x) |
| 129 | +# define be64toh(x) B_SWAP_64(x) |
88 | 130 | # define le64toh(x) (x)
|
89 | 131 |
|
90 | 132 | # elif BYTE_ORDER == BIG_ENDIAN
|
91 | 133 |
|
92 |
| - /* that would be xbox 360 */ |
93 | 134 | # define htobe16(x) (x)
|
94 |
| -# define htole16(x) __builtin_bswap16(x) |
| 135 | +# define htole16(x) B_SWAP_16(x) |
95 | 136 | # define be16toh(x) (x)
|
96 |
| -# define le16toh(x) __builtin_bswap16(x) |
97 |
| - |
| 137 | +# define le16toh(x) B_SWAP_16(x) |
| 138 | + |
98 | 139 | # define htobe32(x) (x)
|
99 |
| -# define htole32(x) __builtin_bswap32(x) |
| 140 | +# define htole32(x) B_SWAP_32(x) |
100 | 141 | # define be32toh(x) (x)
|
101 |
| -# define le32toh(x) __builtin_bswap32(x) |
102 |
| - |
| 142 | +# define le32toh(x) B_SWAP_32(x) |
| 143 | + |
103 | 144 | # define htobe64(x) (x)
|
104 |
| -# define htole64(x) __builtin_bswap64(x) |
| 145 | +# define htole64(x) B_SWAP_64(x) |
105 | 146 | # define be64toh(x) (x)
|
106 |
| -# define le64toh(x) __builtin_bswap64(x) |
| 147 | +# define le64toh(x) B_SWAP_64(x) |
107 | 148 |
|
108 | 149 | # else
|
109 | 150 |
|
110 | 151 | # error byte order not supported
|
111 | 152 |
|
112 | 153 | # endif
|
113 | 154 |
|
114 |
| -# define __BYTE_ORDER BYTE_ORDER |
115 |
| -# define __BIG_ENDIAN BIG_ENDIAN |
116 |
| -# define __LITTLE_ENDIAN LITTLE_ENDIAN |
117 |
| -# define __PDP_ENDIAN PDP_ENDIAN |
118 |
| - |
119 | 155 | #elif defined(__QNXNTO__)
|
120 | 156 |
|
121 | 157 | # include <gulliver.h>
|
|
0 commit comments