-
Notifications
You must be signed in to change notification settings - Fork 1
/
endian.h
150 lines (118 loc) · 2.84 KB
/
endian.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2014-2015 The Bitcoin developers
// where * = (Bit, Lite, PP, Peerunity, Blu, Cat, Solar, URO, ...)
// Previously distributed under the MIT/X11 software license, see the
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Copyright (c) 2014-2015 Troy Benjegerdes, under AGPLv3
// Distributed under the Affero GNU General public license version 3
// file COPYING or http://www.gnu.org/licenses/agpl-3.0.html
#ifndef CODECOIN_COMPAT_ENDIAN_H
#define CODECOIN_COMPAT_ENDIAN_H
/* support Debian now, others later */
#include <stdint.h>
#include "byteswap.h"
#if !defined(MAC_OSX)
/* Linux */
#include <endian.h>
#else
/* MacOS X */
#if defined(WORDS_BIGENDIAN)
inline uint16_t htobe16(uint16_t host_16bits)
{
return host_16bits;
}
inline uint16_t htole16(uint16_t host_16bits)
{
return bswap_16(host_16bits);
}
inline uint16_t be16toh(uint16_t big_endian_16bits)
{
return big_endian_16bits;
}
inline uint16_t le16toh(uint16_t little_endian_16bits)
{
return bswap_16(little_endian_16bits);
}
inline uint32_t htobe32(uint32_t host_32bits)
{
return host_32bits;
}
inline uint32_t htole32(uint32_t host_32bits)
{
return bswap_32(host_32bits);
}
inline uint32_t be32toh(uint32_t big_endian_32bits)
{
return big_endian_32bits;
}
inline uint32_t le32toh(uint32_t little_endian_32bits)
{
return bswap_32(little_endian_32bits);
}
inline uint64_t htobe64(uint64_t host_64bits)
{
return host_64bits;
}
inline uint64_t htole64(uint64_t host_64bits)
{
return bswap_64(host_64bits);
}
inline uint64_t be64toh(uint64_t big_endian_64bits)
{
return big_endian_64bits;
}
inline uint64_t le64toh(uint64_t little_endian_64bits)
{
return bswap_64(little_endian_64bits);
}
#else // WORDS_BIGENDIAN
inline uint16_t htobe16(uint16_t host_16bits)
{
return bswap_16(host_16bits);
}
inline uint16_t htole16(uint16_t host_16bits)
{
return host_16bits;
}
inline uint16_t be16toh(uint16_t big_endian_16bits)
{
return bswap_16(big_endian_16bits);
}
inline uint16_t le16toh(uint16_t little_endian_16bits)
{
return little_endian_16bits;
}
inline uint32_t htobe32(uint32_t host_32bits)
{
return bswap_32(host_32bits);
}
inline uint32_t htole32(uint32_t host_32bits)
{
return host_32bits;
}
inline uint32_t be32toh(uint32_t big_endian_32bits)
{
return bswap_32(big_endian_32bits);
}
inline uint32_t le32toh(uint32_t little_endian_32bits)
{
return little_endian_32bits;
}
inline uint64_t htobe64(uint64_t host_64bits)
{
return bswap_64(host_64bits);
}
inline uint64_t htole64(uint64_t host_64bits)
{
return host_64bits;
}
inline uint64_t be64toh(uint64_t big_endian_64bits)
{
return bswap_64(big_endian_64bits);
}
inline uint64_t le64toh(uint64_t little_endian_64bits)
{
return little_endian_64bits;
}
#endif // WORDS_BIGENDIAN
#endif // MAC_OSX
#endif // BITCOIN_COMPAT_ENDIAN_H