]> git.ipfire.org Git - thirdparty/glibc.git/blob - string/endian.h
0256ee444604aa6d160d82cc4df88e6dc0a337a1
[thirdparty/glibc.git] / string / endian.h
1 /* Copyright (C) 1992-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #ifndef _ENDIAN_H
19 #define _ENDIAN_H 1
20
21 #include <features.h>
22
23 /* Get the definitions of __*_ENDIAN, __BYTE_ORDER, and __FLOAT_WORD_ORDER. */
24 #include <bits/endian.h>
25
26 #ifdef __USE_MISC
27 # define LITTLE_ENDIAN __LITTLE_ENDIAN
28 # define BIG_ENDIAN __BIG_ENDIAN
29 # define PDP_ENDIAN __PDP_ENDIAN
30 # define BYTE_ORDER __BYTE_ORDER
31 #endif
32
33 #if defined __USE_MISC && !defined __ASSEMBLER__
34 /* Conversion interfaces. */
35 # include <bits/byteswap.h>
36 # include <bits/uintn-identity.h>
37
38 # if __BYTE_ORDER == __LITTLE_ENDIAN
39 # define htobe16(x) __bswap_16 (x)
40 # define htole16(x) __uint16_identity (x)
41 # define be16toh(x) __bswap_16 (x)
42 # define le16toh(x) __uint16_identity (x)
43
44 # define htobe32(x) __bswap_32 (x)
45 # define htole32(x) __uint32_identity (x)
46 # define be32toh(x) __bswap_32 (x)
47 # define le32toh(x) __uint32_identity (x)
48
49 # define htobe64(x) __bswap_64 (x)
50 # define htole64(x) __uint64_identity (x)
51 # define be64toh(x) __bswap_64 (x)
52 # define le64toh(x) __uint64_identity (x)
53
54 # else
55 # define htobe16(x) __uint16_identity (x)
56 # define htole16(x) __bswap_16 (x)
57 # define be16toh(x) __uint16_identity (x)
58 # define le16toh(x) __bswap_16 (x)
59
60 # define htobe32(x) __uint32_identity (x)
61 # define htole32(x) __bswap_32 (x)
62 # define be32toh(x) __uint32_identity (x)
63 # define le32toh(x) __bswap_32 (x)
64
65 # define htobe64(x) __uint64_identity (x)
66 # define htole64(x) __bswap_64 (x)
67 # define be64toh(x) __uint64_identity (x)
68 # define le64toh(x) __bswap_64 (x)
69 # endif
70 #endif
71
72 #endif /* endian.h */