1/* zendian.h -- define BYTE_ORDER for endian tests
2 * For conditions of distribution and use, see copyright notice in zlib.h
3 */
4
5#ifndef ENDIAN_H_
6#define ENDIAN_H_
7
8/* First check whether the compiler knows the target __BYTE_ORDER__. */
9#if defined(__BYTE_ORDER__)
10# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
11# if !defined(LITTLE_ENDIAN)
12# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
13# endif
14# if !defined(BYTE_ORDER)
15# define BYTE_ORDER LITTLE_ENDIAN
16# endif
17# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
18# if !defined(BIG_ENDIAN)
19# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
20# endif
21# if !defined(BYTE_ORDER)
22# define BYTE_ORDER BIG_ENDIAN
23# endif
24# endif
25#elif defined(__MINGW32__)
26# include <sys/param.h>
27#elif defined(WIN32) || defined(_WIN32)
28# define LITTLE_ENDIAN 1234
29# define BIG_ENDIAN 4321
30# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined (_M_ARM) || defined (_M_ARM64)
31# define BYTE_ORDER LITTLE_ENDIAN
32# else
33# error Unknown endianness!
34# endif
35#elif defined(__linux__)
36# include <endian.h>
37#elif defined(__APPLE__) || defined(__arm__) || defined(__aarch64__)
38# include <machine/endian.h>
39#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
40# include <sys/endian.h>
41#elif defined(__sun) || defined(sun)
42# include <sys/byteorder.h>
43# if !defined(LITTLE_ENDIAN)
44# define LITTLE_ENDIAN 4321
45# endif
46# if !defined(BIG_ENDIAN)
47# define BIG_ENDIAN 1234
48# endif
49# if !defined(BYTE_ORDER)
50# if defined(_BIG_ENDIAN)
51# define BYTE_ORDER BIG_ENDIAN
52# else
53# define BYTE_ORDER LITTLE_ENDIAN
54# endif
55# endif
56#else
57# include <endian.h>
58#endif
59
60#endif
61