xref: /aosp_15_r20/external/vboot_reference/cgpt/cgpt_endian.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1*8617a60dSAndroid Build Coastguard Worker /* Copyright 2010 The ChromiumOS Authors
2*8617a60dSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
3*8617a60dSAndroid Build Coastguard Worker  * found in the LICENSE file.
4*8617a60dSAndroid Build Coastguard Worker  */
5*8617a60dSAndroid Build Coastguard Worker 
6*8617a60dSAndroid Build Coastguard Worker #ifndef VBOOT_REFERENCE_CGPT_ENDIAN_H_
7*8617a60dSAndroid Build Coastguard Worker #define VBOOT_REFERENCE_CGPT_ENDIAN_H_
8*8617a60dSAndroid Build Coastguard Worker 
9*8617a60dSAndroid Build Coastguard Worker // Newer distros already have this. For those that don't, we add it here.
10*8617a60dSAndroid Build Coastguard Worker #if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
11*8617a60dSAndroid Build Coastguard Worker #include <endian.h>
12*8617a60dSAndroid Build Coastguard Worker #elif defined(__FreeBSD__)
13*8617a60dSAndroid Build Coastguard Worker #include <sys/endian.h>
14*8617a60dSAndroid Build Coastguard Worker #endif
15*8617a60dSAndroid Build Coastguard Worker 
16*8617a60dSAndroid Build Coastguard Worker #ifndef le16toh
17*8617a60dSAndroid Build Coastguard Worker 
18*8617a60dSAndroid Build Coastguard Worker #ifndef HAVE_MACOS
19*8617a60dSAndroid Build Coastguard Worker # include <byteswap.h>
20*8617a60dSAndroid Build Coastguard Worker #endif
21*8617a60dSAndroid Build Coastguard Worker 
22*8617a60dSAndroid Build Coastguard Worker # if __BYTE_ORDER == __LITTLE_ENDIAN
23*8617a60dSAndroid Build Coastguard Worker #  define htobe16(x) __bswap_16 (x)
24*8617a60dSAndroid Build Coastguard Worker #  define htole16(x) (x)
25*8617a60dSAndroid Build Coastguard Worker #  define be16toh(x) __bswap_16 (x)
26*8617a60dSAndroid Build Coastguard Worker #  define le16toh(x) (x)
27*8617a60dSAndroid Build Coastguard Worker 
28*8617a60dSAndroid Build Coastguard Worker #  define htobe32(x) __bswap_32 (x)
29*8617a60dSAndroid Build Coastguard Worker #  define htole32(x) (x)
30*8617a60dSAndroid Build Coastguard Worker #  define be32toh(x) __bswap_32 (x)
31*8617a60dSAndroid Build Coastguard Worker #  define le32toh(x) (x)
32*8617a60dSAndroid Build Coastguard Worker 
33*8617a60dSAndroid Build Coastguard Worker #  define htobe64(x) __bswap_64 (x)
34*8617a60dSAndroid Build Coastguard Worker #  define htole64(x) (x)
35*8617a60dSAndroid Build Coastguard Worker #  define be64toh(x) __bswap_64 (x)
36*8617a60dSAndroid Build Coastguard Worker #  define le64toh(x) (x)
37*8617a60dSAndroid Build Coastguard Worker # else
38*8617a60dSAndroid Build Coastguard Worker #  define htobe16(x) (x)
39*8617a60dSAndroid Build Coastguard Worker #  define htole16(x) __bswap_16 (x)
40*8617a60dSAndroid Build Coastguard Worker #  define be16toh(x) (x)
41*8617a60dSAndroid Build Coastguard Worker #  define le16toh(x) __bswap_16 (x)
42*8617a60dSAndroid Build Coastguard Worker 
43*8617a60dSAndroid Build Coastguard Worker #  define htobe32(x) (x)
44*8617a60dSAndroid Build Coastguard Worker #  define htole32(x) __bswap_32 (x)
45*8617a60dSAndroid Build Coastguard Worker #  define be32toh(x) (x)
46*8617a60dSAndroid Build Coastguard Worker #  define le32toh(x) __bswap_32 (x)
47*8617a60dSAndroid Build Coastguard Worker 
48*8617a60dSAndroid Build Coastguard Worker #  define htobe64(x) (x)
49*8617a60dSAndroid Build Coastguard Worker #  define htole64(x) __bswap_64 (x)
50*8617a60dSAndroid Build Coastguard Worker #  define be64toh(x) (x)
51*8617a60dSAndroid Build Coastguard Worker #  define le64toh(x) __bswap_64 (x)
52*8617a60dSAndroid Build Coastguard Worker # endif
53*8617a60dSAndroid Build Coastguard Worker 
54*8617a60dSAndroid Build Coastguard Worker #endif
55*8617a60dSAndroid Build Coastguard Worker 
56*8617a60dSAndroid Build Coastguard Worker #endif  /* VBOOT_REFERENCE_CGPT_ENDIAN_H_ */
57