]> git.ipfire.org Git - thirdparty/glibc.git/blame - string/endian.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / string / endian.h
CommitLineData
04277e02 1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
54d79e99
UD
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
41bdb6e2
AJ
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.
54d79e99
UD
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
41bdb6e2 12 Lesser General Public License for more details.
54d79e99 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4
RM
17
18#ifndef _ENDIAN_H
19#define _ENDIAN_H 1
5107cf1d 20
28f540f4
RM
21#include <features.h>
22
7603ea28
UD
23/* Definitions for byte order, according to significance of bytes,
24 from low addresses to high addresses. The value is what you get by
25 putting '4' in the most significant byte, '3' in the second most
26 significant byte, '2' in the second least significant byte, and '1'
27 in the least significant byte, and then writing down one digit for
28 each byte, starting with the byte at the lowest address at the left,
29 and proceeding to the byte with the highest address at the right. */
28f540f4
RM
30
31#define __LITTLE_ENDIAN 1234
32#define __BIG_ENDIAN 4321
33#define __PDP_ENDIAN 3412
34
35/* This file defines `__BYTE_ORDER' for the particular machine. */
5107cf1d 36#include <bits/endian.h>
28f540f4 37
48252123
UD
38/* Some machines may need to use a different endianness for floating point
39 values. */
40#ifndef __FLOAT_WORD_ORDER
41# define __FLOAT_WORD_ORDER __BYTE_ORDER
42#endif
43
498afc54 44#ifdef __USE_MISC
dfd2257a
UD
45# define LITTLE_ENDIAN __LITTLE_ENDIAN
46# define BIG_ENDIAN __BIG_ENDIAN
47# define PDP_ENDIAN __PDP_ENDIAN
48# define BYTE_ORDER __BYTE_ORDER
28f540f4
RM
49#endif
50
ca1cde9e
GM
51#if __BYTE_ORDER == __LITTLE_ENDIAN
52# define __LONG_LONG_PAIR(HI, LO) LO, HI
53#elif __BYTE_ORDER == __BIG_ENDIAN
54# define __LONG_LONG_PAIR(HI, LO) HI, LO
55#endif
56
2f9a1be8 57
498afc54 58#if defined __USE_MISC && !defined __ASSEMBLER__
2f9a1be8 59/* Conversion interfaces. */
e92799fc 60# include <bits/byteswap.h>
6a1cefac 61# include <bits/uintn-identity.h>
e92799fc
UD
62
63# if __BYTE_ORDER == __LITTLE_ENDIAN
64# define htobe16(x) __bswap_16 (x)
6a1cefac 65# define htole16(x) __uint16_identity (x)
e92799fc 66# define be16toh(x) __bswap_16 (x)
6a1cefac 67# define le16toh(x) __uint16_identity (x)
e92799fc
UD
68
69# define htobe32(x) __bswap_32 (x)
6a1cefac 70# define htole32(x) __uint32_identity (x)
e92799fc 71# define be32toh(x) __bswap_32 (x)
6a1cefac 72# define le32toh(x) __uint32_identity (x)
e92799fc 73
6a57d931 74# define htobe64(x) __bswap_64 (x)
6a1cefac 75# define htole64(x) __uint64_identity (x)
6a57d931 76# define be64toh(x) __bswap_64 (x)
6a1cefac 77# define le64toh(x) __uint64_identity (x)
b1aa60f3 78
e92799fc 79# else
6a1cefac 80# define htobe16(x) __uint16_identity (x)
e92799fc 81# define htole16(x) __bswap_16 (x)
6a1cefac 82# define be16toh(x) __uint16_identity (x)
e92799fc
UD
83# define le16toh(x) __bswap_16 (x)
84
6a1cefac 85# define htobe32(x) __uint32_identity (x)
e92799fc 86# define htole32(x) __bswap_32 (x)
6a1cefac 87# define be32toh(x) __uint32_identity (x)
e92799fc
UD
88# define le32toh(x) __bswap_32 (x)
89
6a1cefac 90# define htobe64(x) __uint64_identity (x)
6a57d931 91# define htole64(x) __bswap_64 (x)
6a1cefac 92# define be64toh(x) __uint64_identity (x)
6a57d931 93# define le64toh(x) __bswap_64 (x)
e92799fc 94# endif
2f9a1be8
UD
95#endif
96
28f540f4 97#endif /* endian.h */