2 * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _COMPAT_ENDIAN_H
18 #define _COMPAT_ENDIAN_H
22 # define LITTLE_ENDIAN 1234
24 # define BIG_ENDIAN 4321
25 # undef UNKNOWN_ENDIAN
26 # define UNKNOWN_ENDIAN 0
29 * Attempt to guess endianness.
30 * Solaris may define _LITTLE_ENDIAN and _BIG_ENDIAN to 1
31 * HP-UX may define __LITTLE_ENDIAN__ and __BIG_ENDIAN__ to 1
32 * Otherwise, check for cpu-specific cpp defines.
33 * Note that some CPUs are bi-endian, including: arm, powerpc, alpha,
34 * sparc64, mips, hppa, sh4 and ia64.
35 * We just check for the most common uses.
38 # if defined(__BYTE_ORDER)
39 # define BYTE_ORDER __BYTE_ORDER
40 # elif defined(_BYTE_ORDER)
41 # define BYTE_ORDER _BYTE_ORDER
42 # elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__)
43 # define BYTE_ORDER LITTLE_ENDIAN
44 # elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
45 # define BYTE_ORDER BIG_ENDIAN
46 # elif defined(__alpha__) || defined(__alpha) || defined(__amd64) || \
47 defined(BIT_ZERO_ON_RIGHT) || defined(i386) || defined(__i386) || \
48 defined(MIPSEL) || defined(_MIPSEL) || defined(ns32000) || \
49 defined(__ns3200) || defined(sun386) || defined(vax) || \
50 defined(__vax) || defined(__x86__) || \
51 (defined(sun) && defined(__powerpc)) || \
52 (!defined(__hpux) && defined(__ia64))
53 # define BYTE_ORDER LITTLE_ENDIAN
54 # elif defined(__68k__) || defined(apollo) || defined(BIT_ZERO_ON_LEFT) || \
55 defined(__convex__) || defined(_CRAY) || defined(DGUX) || \
56 defined(__hppa) || defined(__hp9000) || defined(__hp9000s300) || \
57 defined(__hp9000s700) || defined(__hp3000s900) || \
58 defined(ibm032) || defined(ibm370) || defined(_IBMR2) || \
59 defined(is68k) || defined(mc68000) || defined(m68k) || \
60 defined(__m68k) || defined(m88k) || defined(__m88k) || \
61 defined(MIPSEB) || defined(_MIPSEB) || defined(MPE) || \
62 defined(pyr) || defined(__powerpc) || defined(__powerpc__) || \
63 defined(sel) || defined(__sparc) || defined(__sparc__) || \
64 defined(tahoe) || (defined(__hpux) && defined(__ia64)) || \
65 (defined(sun) && defined(__powerpc))
66 # define BYTE_ORDER BIG_ENDIAN
68 # define BYTE_ORDER UNKNOWN_ENDIAN
70 #endif /* BYTE_ORDER */
72 #endif /* _COMPAT_ENDIAN_H */