Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/include/compat/endian.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2013, 2022 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef COMPAT_ENDIAN_H
20
#define COMPAT_ENDIAN_H
21
22
#ifndef BYTE_ORDER
23
# undef LITTLE_ENDIAN
24
# define LITTLE_ENDIAN 1234
25
# undef BIG_ENDIAN
26
# define BIG_ENDIAN 4321
27
# undef UNKNOWN_ENDIAN
28
# define UNKNOWN_ENDIAN 0
29
30
/*
31
* Attempt to guess endianness.
32
* Solaris may define _LITTLE_ENDIAN and _BIG_ENDIAN to 1
33
* HP-UX may define __LITTLE_ENDIAN__ and __BIG_ENDIAN__ to 1
34
* Otherwise, check for cpu-specific cpp defines.
35
* Note that some CPUs are bi-endian, including: arm, powerpc, alpha,
36
* sparc64, mips, hppa, sh4 and ia64.
37
* We just check for the most common uses.
38
*/
39
40
# if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
41
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
42
# define BYTE_ORDER LITTLE_ENDIAN
43
# elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
44
(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
45
# define BYTE_ORDER BIG_ENDIAN
46
# elif defined(__BYTE_ORDER)
47
# define BYTE_ORDER __BYTE_ORDER
48
# elif defined(_BYTE_ORDER)
49
# define BYTE_ORDER _BYTE_ORDER
50
# elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__)
51
# define BYTE_ORDER LITTLE_ENDIAN
52
# elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
53
# define BYTE_ORDER BIG_ENDIAN
54
# elif defined(__alpha__) || defined(__alpha) || defined(__amd64) || \
55
defined(BIT_ZERO_ON_RIGHT) || defined(i386) || defined(__i386) || \
56
defined(MIPSEL) || defined(_MIPSEL) || defined(ns32000) || \
57
defined(__ns3200) || defined(sun386) || defined(vax) || \
58
defined(__vax) || defined(__x86__) || defined(__riscv) || \
59
(defined(sun) && defined(__powerpc)) || \
60
(!defined(__hpux) && defined(__ia64))
61
# define BYTE_ORDER LITTLE_ENDIAN
62
# elif defined(__68k__) || defined(apollo) || defined(BIT_ZERO_ON_LEFT) || \
63
defined(__convex__) || defined(_CRAY) || defined(DGUX) || \
64
defined(__hppa) || defined(__hp9000) || defined(__hp9000s300) || \
65
defined(__hp9000s700) || defined(__hp3000s900) || \
66
defined(ibm032) || defined(ibm370) || defined(_IBMR2) || \
67
defined(is68k) || defined(mc68000) || defined(m68k) || \
68
defined(__m68k) || defined(m88k) || defined(__m88k) || \
69
defined(MIPSEB) || defined(_MIPSEB) || defined(MPE) || \
70
defined(pyr) || defined(__powerpc) || defined(__powerpc__) || \
71
defined(sel) || defined(__sparc) || defined(__sparc__) || \
72
defined(tahoe) || (defined(__hpux) && defined(__ia64)) || \
73
(defined(sun) && defined(__powerpc))
74
# define BYTE_ORDER BIG_ENDIAN
75
# else
76
# define BYTE_ORDER UNKNOWN_ENDIAN
77
# endif
78
#endif /* BYTE_ORDER */
79
80
#endif /* COMPAT_ENDIAN_H */
81
82