OSDN Git Service

mkostemp: fix implementation
[uclinux-h8/uClibc.git] / include / endian.h
1 /* Copyright (C) 1992, 1996, 1997, 2000 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    <http://www.gnu.org/licenses/>.  */
17
18 #ifndef _ENDIAN_H
19 #define _ENDIAN_H       1
20
21 #include <features.h>
22
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.  */
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.  */
36 #include <bits/endian.h>
37
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
44 #ifdef  __USE_BSD
45 # define LITTLE_ENDIAN  __LITTLE_ENDIAN
46 # define BIG_ENDIAN     __BIG_ENDIAN
47 # define PDP_ENDIAN     __PDP_ENDIAN
48 # define BYTE_ORDER     __BYTE_ORDER
49 #endif
50
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
57 #ifdef _LIBC
58 # ifndef __ASSEMBLER__
59 #  include <stdint.h>
60 #  define OFF_HI(offset) (offset >> 31)
61 #  define OFF_LO(offset) (offset)
62 #  define OFF64_HI(offset) (uint32_t)(offset >> 32)
63 #  define OFF64_LO(offset) (uint32_t)(offset & 0xffffffff)
64 #  define OFF_HI_LO(offset) __LONG_LONG_PAIR(OFF_HI(offset), OFF_LO(offset))
65 #  define OFF64_HI_LO(offset) __LONG_LONG_PAIR(OFF64_HI(offset), OFF64_LO(offset))
66 # endif
67 #endif
68
69 #ifdef __USE_BSD
70 /* Conversion interfaces.  */
71 # include <byteswap.h>
72
73 # if __BYTE_ORDER == __LITTLE_ENDIAN
74 #  define htobe16(x) __bswap_16 (x)
75 #  define htole16(x) (x)
76 #  define be16toh(x) __bswap_16 (x)
77 #  define le16toh(x) (x)
78
79 #  define htobe32(x) __bswap_32 (x)
80 #  define htole32(x) (x)
81 #  define be32toh(x) __bswap_32 (x)
82 #  define le32toh(x) (x)
83
84 #  define htobe64(x) __bswap_64 (x)
85 #  define htole64(x) (x)
86 #  define be64toh(x) __bswap_64 (x)
87 #  define le64toh(x) (x)
88 # else
89 #  define htobe16(x) (x)
90 #  define htole16(x) __bswap_16 (x)
91 #  define be16toh(x) (x)
92 #  define le16toh(x) __bswap_16 (x)
93
94 #  define htobe32(x) (x)
95 #  define htole32(x) __bswap_32 (x)
96 #  define be32toh(x) (x)
97 #  define le32toh(x) __bswap_32 (x)
98
99 #  define htobe64(x) (x)
100 #  define htole64(x) __bswap_64 (x)
101 #  define be64toh(x) (x)
102 #  define le64toh(x) __bswap_64 (x)
103 # endif
104 #endif
105
106 #endif  /* endian.h */