Raven Core  3.0.0
P2P Digital Currency
endian.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_COMPAT_ENDIAN_H
7 #define RAVEN_COMPAT_ENDIAN_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "config/raven-config.h"
11 #endif
12 
13 #include "compat/byteswap.h"
14 
15 #include <stdint.h>
16 
17 #if defined(HAVE_ENDIAN_H)
18 #include <endian.h>
19 #elif defined(HAVE_SYS_ENDIAN_H)
20 #include <sys/endian.h>
21 #endif
22 
23 #if defined(WORDS_BIGENDIAN)
24 
25 #if HAVE_DECL_HTOBE16 == 0
26 inline uint16_t htobe16(uint16_t host_16bits)
27 {
28  return host_16bits;
29 }
30 #endif // HAVE_DECL_HTOBE16
31 
32 #if HAVE_DECL_HTOLE16 == 0
33 inline uint16_t htole16(uint16_t host_16bits)
34 {
35  return bswap_16(host_16bits);
36 }
37 #endif // HAVE_DECL_HTOLE16
38 
39 #if HAVE_DECL_BE16TOH == 0
40 inline uint16_t be16toh(uint16_t big_endian_16bits)
41 {
42  return big_endian_16bits;
43 }
44 #endif // HAVE_DECL_BE16TOH
45 
46 #if HAVE_DECL_LE16TOH == 0
47 inline uint16_t le16toh(uint16_t little_endian_16bits)
48 {
49  return bswap_16(little_endian_16bits);
50 }
51 #endif // HAVE_DECL_LE16TOH
52 
53 #if HAVE_DECL_HTOBE32 == 0
54 inline uint32_t htobe32(uint32_t host_32bits)
55 {
56  return host_32bits;
57 }
58 #endif // HAVE_DECL_HTOBE32
59 
60 #if HAVE_DECL_HTOLE32 == 0
61 inline uint32_t htole32(uint32_t host_32bits)
62 {
63  return bswap_32(host_32bits);
64 }
65 #endif // HAVE_DECL_HTOLE32
66 
67 #if HAVE_DECL_BE32TOH == 0
68 inline uint32_t be32toh(uint32_t big_endian_32bits)
69 {
70  return big_endian_32bits;
71 }
72 #endif // HAVE_DECL_BE32TOH
73 
74 #if HAVE_DECL_LE32TOH == 0
75 inline uint32_t le32toh(uint32_t little_endian_32bits)
76 {
77  return bswap_32(little_endian_32bits);
78 }
79 #endif // HAVE_DECL_LE32TOH
80 
81 #if HAVE_DECL_HTOBE64 == 0
82 inline uint64_t htobe64(uint64_t host_64bits)
83 {
84  return host_64bits;
85 }
86 #endif // HAVE_DECL_HTOBE64
87 
88 #if HAVE_DECL_HTOLE64 == 0
89 inline uint64_t htole64(uint64_t host_64bits)
90 {
91  return bswap_64(host_64bits);
92 }
93 #endif // HAVE_DECL_HTOLE64
94 
95 #if HAVE_DECL_BE64TOH == 0
96 inline uint64_t be64toh(uint64_t big_endian_64bits)
97 {
98  return big_endian_64bits;
99 }
100 #endif // HAVE_DECL_BE64TOH
101 
102 #if HAVE_DECL_LE64TOH == 0
103 inline uint64_t le64toh(uint64_t little_endian_64bits)
104 {
105  return bswap_64(little_endian_64bits);
106 }
107 #endif // HAVE_DECL_LE64TOH
108 
109 #else // WORDS_BIGENDIAN
110 
111 #if HAVE_DECL_HTOBE16 == 0
112 inline uint16_t htobe16(uint16_t host_16bits)
113 {
114  return bswap_16(host_16bits);
115 }
116 #endif // HAVE_DECL_HTOBE16
117 
118 #if HAVE_DECL_HTOLE16 == 0
119 inline uint16_t htole16(uint16_t host_16bits)
120 {
121  return host_16bits;
122 }
123 #endif // HAVE_DECL_HTOLE16
124 
125 #if HAVE_DECL_BE16TOH == 0
126 inline uint16_t be16toh(uint16_t big_endian_16bits)
127 {
128  return bswap_16(big_endian_16bits);
129 }
130 #endif // HAVE_DECL_BE16TOH
131 
132 #if HAVE_DECL_LE16TOH == 0
133 inline uint16_t le16toh(uint16_t little_endian_16bits)
134 {
135  return little_endian_16bits;
136 }
137 #endif // HAVE_DECL_LE16TOH
138 
139 #if HAVE_DECL_HTOBE32 == 0
140 inline uint32_t htobe32(uint32_t host_32bits)
141 {
142  return bswap_32(host_32bits);
143 }
144 #endif // HAVE_DECL_HTOBE32
145 
146 #if HAVE_DECL_HTOLE32 == 0
147 inline uint32_t htole32(uint32_t host_32bits)
148 {
149  return host_32bits;
150 }
151 #endif // HAVE_DECL_HTOLE32
152 
153 #if HAVE_DECL_BE32TOH == 0
154 inline uint32_t be32toh(uint32_t big_endian_32bits)
155 {
156  return bswap_32(big_endian_32bits);
157 }
158 #endif // HAVE_DECL_BE32TOH
159 
160 #if HAVE_DECL_LE32TOH == 0
161 inline uint32_t le32toh(uint32_t little_endian_32bits)
162 {
163  return little_endian_32bits;
164 }
165 #endif // HAVE_DECL_LE32TOH
166 
167 #if HAVE_DECL_HTOBE64 == 0
168 inline uint64_t htobe64(uint64_t host_64bits)
169 {
170  return bswap_64(host_64bits);
171 }
172 #endif // HAVE_DECL_HTOBE64
173 
174 #if HAVE_DECL_HTOLE64 == 0
175 inline uint64_t htole64(uint64_t host_64bits)
176 {
177  return host_64bits;
178 }
179 #endif // HAVE_DECL_HTOLE64
180 
181 #if HAVE_DECL_BE64TOH == 0
182 inline uint64_t be64toh(uint64_t big_endian_64bits)
183 {
184  return bswap_64(big_endian_64bits);
185 }
186 #endif // HAVE_DECL_BE64TOH
187 
188 #if HAVE_DECL_LE64TOH == 0
189 inline uint64_t le64toh(uint64_t little_endian_64bits)
190 {
191  return little_endian_64bits;
192 }
193 #endif // HAVE_DECL_LE64TOH
194 
195 #endif // WORDS_BIGENDIAN
196 
197 #endif // RAVEN_COMPAT_ENDIAN_H
uint64_t htobe64(uint64_t host_64bits)
Definition: endian.h:168
uint32_t be32toh(uint32_t big_endian_32bits)
Definition: endian.h:154
uint32_t htole32(uint32_t host_32bits)
Definition: endian.h:147
uint32_t bswap_32(uint32_t x)
Definition: byteswap.h:44
uint32_t htobe32(uint32_t host_32bits)
Definition: endian.h:140
uint64_t be64toh(uint64_t big_endian_64bits)
Definition: endian.h:182
uint16_t htobe16(uint16_t host_16bits)
Definition: endian.h:112
uint16_t bswap_16(uint16_t x)
Definition: byteswap.h:37
uint16_t le16toh(uint16_t little_endian_16bits)
Definition: endian.h:133
uint16_t htole16(uint16_t host_16bits)
Definition: endian.h:119
uint64_t le64toh(uint64_t little_endian_64bits)
Definition: endian.h:189
uint64_t bswap_64(uint64_t x)
Definition: byteswap.h:52
uint16_t be16toh(uint16_t big_endian_16bits)
Definition: endian.h:126
uint64_t htole64(uint64_t host_64bits)
Definition: endian.h:175
uint32_t le32toh(uint32_t little_endian_32bits)
Definition: endian.h:161