Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / tools / include / tools / endian.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TOOLS_ENDIAN_H
3 #define _TOOLS_ENDIAN_H
4
5 #include <byteswap.h>
6
7 #if __BYTE_ORDER == __LITTLE_ENDIAN
8
9 #ifndef htole16
10 #define htole16(x) (x)
11 #endif
12 #ifndef htole32
13 #define htole32(x) (x)
14 #endif
15 #ifndef htole64
16 #define htole64(x) (x)
17 #endif
18
19 #ifndef le16toh
20 #define le16toh(x) (x)
21 #endif
22
23 #ifndef le32toh
24 #define le32toh(x) (x)
25 #endif
26
27 #ifndef le64toh
28 #define le64toh(x) (x)
29 #endif
30
31 #else /* __BYTE_ORDER */
32
33 #ifndef htole16
34 #define htole16(x) __bswap_16(x)
35 #endif
36 #ifndef htole32
37 #define htole32(x) __bswap_32(x)
38 #endif
39 #ifndef htole64
40 #define htole64(x) __bswap_64(x)
41 #endif
42
43 #ifndef le16toh
44 #define le16toh(x) __bswap_16(x)
45 #endif
46
47 #ifndef le32toh
48 #define le32toh(x) __bswap_32(x)
49 #endif
50
51 #ifndef le64toh
52 #define le64toh(x) __bswap_64(x)
53 #endif
54
55 #endif
56
57 #endif /* _TOOLS_ENDIAN_H */