|
4 | 4 | // be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it |
5 | 5 | // an example on how to get the endian conversion functions on different platforms. |
6 | 6 |
|
7 | | -#ifndef PORTABLE_ENDIAN_H__ |
8 | | -#define PORTABLE_ENDIAN_H__ |
| 7 | +// updates from https://github.com/mikepb/endian.h/issues/4 |
| 8 | + |
| 9 | +#ifndef ENDIAN_H |
| 10 | +#define ENDIAN_H |
9 | 11 |
|
10 | 12 | #if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) |
11 | 13 |
|
12 | 14 | # define __WINDOWS__ |
13 | 15 |
|
14 | 16 | #endif |
15 | 17 |
|
16 | | -#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(__EMSCRIPTEN__) |
| 18 | +#if defined(HAVE_ENDIAN_H) || \ |
| 19 | + defined(__linux__) || \ |
| 20 | + defined(__GNU__) || \ |
| 21 | + defined(__OpenBSD__) || \ |
| 22 | + defined(__CYGWIN__) || \ |
| 23 | + defined(__MSYS__) || \ |
| 24 | + defined(__EMSCRIPTEN__) |
| 25 | + |
| 26 | +# include <endian.h> |
17 | 27 |
|
18 | | -# include <endian.h> |
| 28 | +#elif defined(HAVE_SYS_ENDIAN_H) || \ |
| 29 | + defined(__FreeBSD__) || \ |
| 30 | + defined(__NetBSD__) || \ |
| 31 | + defined(__DragonFly__) |
| 32 | + |
| 33 | +# include <sys/endian.h> |
19 | 34 |
|
20 | 35 | #elif defined(__APPLE__) |
21 | 36 | # define __BYTE_ORDER BYTE_ORDER |
|
75 | 90 | # error byte order not supported |
76 | 91 | # endif |
77 | 92 | # endif |
78 | | -#elif defined(__OpenBSD__) |
79 | | - |
80 | | -# include <endian.h> |
81 | | - |
82 | | -# define __BYTE_ORDER BYTE_ORDER |
83 | | -# define __BIG_ENDIAN BIG_ENDIAN |
84 | | -# define __LITTLE_ENDIAN LITTLE_ENDIAN |
85 | | -# define __PDP_ENDIAN PDP_ENDIAN |
86 | | - |
87 | | -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) |
88 | | - |
89 | | -# include <sys/endian.h> |
90 | | - |
91 | | -# define be16toh(x) betoh16(x) |
92 | | -# define le16toh(x) letoh16(x) |
93 | | - |
94 | | -# define be32toh(x) betoh32(x) |
95 | | -# define le32toh(x) letoh32(x) |
96 | | - |
97 | | -# define be64toh(x) betoh64(x) |
98 | | -# define le64toh(x) letoh64(x) |
99 | 93 |
|
100 | 94 | #elif defined(__WINDOWS__) |
101 | 95 |
|
102 | | - |
103 | 96 | # if defined(_MSC_VER) && !defined(__clang__) |
104 | 97 | # include <stdlib.h> |
105 | 98 | # define B_SWAP_16(x) _byteswap_ushort(x) |
|
0 commit comments