.
[glibc/history.git] / string / endian.h
blob37d030a2520d0dc72ed9ab704017b3288102bd0b
1 /* Copyright (C) 1992, 1996, 1997, 2000, 2008 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #ifndef _ENDIAN_H
20 #define _ENDIAN_H 1
22 #include <features.h>
24 /* Definitions for byte order, according to significance of bytes,
25 from low addresses to high addresses. The value is what you get by
26 putting '4' in the most significant byte, '3' in the second most
27 significant byte, '2' in the second least significant byte, and '1'
28 in the least significant byte, and then writing down one digit for
29 each byte, starting with the byte at the lowest address at the left,
30 and proceeding to the byte with the highest address at the right. */
32 #define __LITTLE_ENDIAN 1234
33 #define __BIG_ENDIAN 4321
34 #define __PDP_ENDIAN 3412
36 /* This file defines `__BYTE_ORDER' for the particular machine. */
37 #include <bits/endian.h>
39 /* Some machines may need to use a different endianness for floating point
40 values. */
41 #ifndef __FLOAT_WORD_ORDER
42 # define __FLOAT_WORD_ORDER __BYTE_ORDER
43 #endif
45 #ifdef __USE_BSD
46 # define LITTLE_ENDIAN __LITTLE_ENDIAN
47 # define BIG_ENDIAN __BIG_ENDIAN
48 # define PDP_ENDIAN __PDP_ENDIAN
49 # define BYTE_ORDER __BYTE_ORDER
50 #endif
52 #if __BYTE_ORDER == __LITTLE_ENDIAN
53 # define __LONG_LONG_PAIR(HI, LO) LO, HI
54 #elif __BYTE_ORDER == __BIG_ENDIAN
55 # define __LONG_LONG_PAIR(HI, LO) HI, LO
56 #endif
59 #ifdef __USE_BSD
60 /* Conversion interfaces. */
61 # include <bits/byteswap.h>
63 # if __BYTE_ORDER == __LITTLE_ENDIAN
64 # define htobe16(x) __bswap_16 (x)
65 # define htole16(x) (x)
66 # define be16toh(x) __bswap_16 (x)
67 # define le16toh(x) (x)
69 # define htobe32(x) __bswap_32 (x)
70 # define htole32(x) (x)
71 # define be32toh(x) __bswap_32 (x)
72 # define le32toh(x) (x)
74 # define htobe64(x) __bswap_64 (x)
75 # define htole64(x) (x)
76 # define be64toh(x) __bswap_64 (x)
77 # define le64toh(x) (x)
78 # else
79 # define htobe16(x) (x)
80 # define htole16(x) __bswap_16 (x)
81 # define be16toh(x) (x)
82 # define le16toh(x) __bswap_16 (x)
84 # define htobe32(x) (x)
85 # define htole32(x) __bswap_32 (x)
86 # define be32toh(x) (x)
87 # define le32toh(x) __bswap_32 (x)
89 # define htobe64(x) (x)
90 # define htole64(x) __bswap_64 (x)
91 # define be64toh(x) (x)
92 # define le64toh(x) __bswap_64 (x)
93 # endif
94 #endif
96 #endif /* endian.h */