bt2: stream activity messages: create with unknown/infinite default CS
[babeltrace.git] / src / compat / endian.h
1 #ifndef _BABELTRACE_ENDIAN_H
2 #define _BABELTRACE_ENDIAN_H
3
4 /*
5 * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * endian.h compatibility layer.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #ifdef __FreeBSD__
29 #include <machine/endian.h>
30
31 #elif defined(__sun__)
32 #include <sys/byteorder.h>
33
34 #ifndef __BIG_ENDIAN
35 #define __BIG_ENDIAN 4321
36 #endif
37 #ifndef __LITTLE_ENDIAN
38 #define __LITTLE_ENDIAN 1234
39 #endif
40
41 #ifdef _LITTLE_ENDIAN
42 #define __BYTE_ORDER __LITTLE_ENDIAN
43 #endif
44
45 #ifdef _BIG_ENDIAN
46 #define __BYTE_ORDER __BIG_ENDIAN
47 #endif
48
49 #define LITTLE_ENDIAN __LITTLE_ENDIAN
50 #define BIG_ENDIAN __BIG_ENDIAN
51 #define BYTE_ORDER __BYTE_ORDER
52
53 #define betoh16(x) BE_16(x)
54 #define letoh16(x) LE_16(x)
55 #define betoh32(x) BE_32(x)
56 #define letoh32(x) LE_32(x)
57 #define betoh64(x) BE_64(x)
58 #define letoh64(x) LE_64(x)
59 #define htobe16(x) BE_16(x)
60 #define be16toh(x) BE_16(x)
61 #define htobe32(x) BE_32(x)
62 #define be32toh(x) BE_32(x)
63 #define htobe64(x) BE_64(x)
64 #define be64toh(x) BE_64(x)
65
66 #elif defined(__MINGW32__)
67 #include <stdint.h>
68
69 #ifndef __BIG_ENDIAN
70 #define __BIG_ENDIAN 4321
71 #endif
72 #ifndef __LITTLE_ENDIAN
73 #define __LITTLE_ENDIAN 1234
74 #endif
75
76 #ifndef __BYTE_ORDER
77 #define __BYTE_ORDER __LITTLE_ENDIAN
78 #endif
79
80 #define LITTLE_ENDIAN __LITTLE_ENDIAN
81 #define BIG_ENDIAN __BIG_ENDIAN
82 #define PDP_ENDIAN __PDP_ENDIAN
83 #define BYTE_ORDER __BYTE_ORDER
84
85 #define htobe16(x) (uint16_t) _byteswap_ushort(x)
86 #define htole16(x) (x)
87 #define be16toh(x) (uint16_t) _byteswap_ushort(x)
88 #define le16toh(x) (x)
89
90 #define htobe32(x) (uint32_t) _byteswap_ulong(x)
91 #define htole32(x) (x)
92 #define be32toh(x) (uint32_t) _byteswap_ulong(x)
93 #define le32toh(x) (x)
94
95 #define htobe64(x) (uint64_t) _byteswap_uint64(x)
96 #define htole64(x) (x)
97 #define be64toh(x) (uint64_t) _byteswap_uint64(x)
98 #define le64toh(x) (x)
99
100 #elif defined(__APPLE__)
101 # include <machine/endian.h>
102 # include <libkern/OSByteOrder.h>
103
104 # if BYTE_ORDER == LITTLE_ENDIAN
105 # define htobe16(x) OSSwapConstInt16(x)
106 # define htole16(x) (x)
107 # define be16toh(x) OSSwapConstInt16(x)
108 # define le16toh(x) (x)
109
110 # define htobe32(x) OSSwapConstInt32(x)
111 # define htole32(x) (x)
112 # define be32toh(x) OSSwapConstInt32(x)
113 # define le32toh(x) (x)
114
115 # define htobe64(x) OSSwapConstInt64(x)
116 # define htole64(x) (x)
117 # define be64toh(x) OSSwapConstInt64(x)
118 # define le64toh(x) (x)
119
120 # else /* BYTE_ORDER == LITTLE_ENDIAN */
121 # define htobe16(x) (x)
122 # define htole16(x) OSSwapConstInt16(x)
123 # define be16toh(x) (x)
124 # define le16toh(x) OSSwapConstInt16(x)
125
126 # define htobe32(x) (x)
127 # define htole32(x) OSSwapConstInt32(x)
128 # define be32toh(x) (x)
129 # define le32toh(x) OSSwapConstInt32(x)
130
131 # define htobe64(x) (x)
132 # define htole64(x) OSSwapConstInt64(x)
133 # define be64toh(x) (x)
134 # define le64toh(x) OSSwapConstInt64(x)
135 # endif
136
137 #else
138 #include <endian.h>
139
140 /*
141 * htobe/betoh are not defined for glibc < 2.9, so add them explicitly
142 * if they are missing.
143 */
144 # ifdef __USE_BSD
145 /* Conversion interfaces. */
146 # include <byteswap.h>
147
148 # if __BYTE_ORDER == __LITTLE_ENDIAN
149 # ifndef htobe16
150 # define htobe16(x) __bswap_16(x)
151 # endif
152 # ifndef htole16
153 # define htole16(x) (x)
154 # endif
155 # ifndef be16toh
156 # define be16toh(x) __bswap_16(x)
157 # endif
158 # ifndef le16toh
159 # define le16toh(x) (x)
160 # endif
161
162 # ifndef htobe32
163 # define htobe32(x) __bswap_32(x)
164 # endif
165 # ifndef htole32
166 # define htole32(x) (x)
167 # endif
168 # ifndef be32toh
169 # define be32toh(x) __bswap_32(x)
170 # endif
171 # ifndef le32toh
172 # define le32toh(x) (x)
173 # endif
174
175 # ifndef htobe64
176 # define htobe64(x) __bswap_64(x)
177 # endif
178 # ifndef htole64
179 # define htole64(x) (x)
180 # endif
181 # ifndef be64toh
182 # define be64toh(x) __bswap_64(x)
183 # endif
184 # ifndef le64toh
185 # define le64toh(x) (x)
186 # endif
187
188 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
189 # ifndef htobe16
190 # define htobe16(x) (x)
191 # endif
192 # ifndef htole16
193 # define htole16(x) __bswap_16(x)
194 # endif
195 # ifndef be16toh
196 # define be16toh(x) (x)
197 # endif
198 # ifndef le16toh
199 # define le16toh(x) __bswap_16(x)
200 # endif
201
202 # ifndef htobe32
203 # define htobe32(x) (x)
204 # endif
205 # ifndef htole32
206 # define htole32(x) __bswap_32(x)
207 # endif
208 # ifndef be32toh
209 # define be32toh(x) (x)
210 # endif
211 # ifndef le32toh
212 # define le32toh(x) __bswap_32(x)
213 # endif
214
215 # ifndef htobe64
216 # define htobe64(x) (x)
217 # endif
218 # ifndef htole64
219 # define htole64(x) __bswap_64(x)
220 # endif
221 # ifndef be64toh
222 # define be64toh(x) (x)
223 # endif
224 # ifndef le64toh
225 # define le64toh(x) __bswap_64(x)
226 # endif
227
228 # endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
229 # endif /* __USE_BSD */
230 #endif /* else -- __FreeBSD__ */
231
232 #ifndef FLOAT_WORD_ORDER
233 #ifdef __FLOAT_WORD_ORDER
234 #define FLOAT_WORD_ORDER __FLOAT_WORD_ORDER
235 #else /* __FLOAT_WORD_ORDER */
236 #define FLOAT_WORD_ORDER BYTE_ORDER
237 #endif /* __FLOAT_WORD_ORDER */
238 #endif /* FLOAT_WORD_ORDER */
239
240 #endif /* _BABELTRACE_ENDIAN_H */
This page took 0.040646 seconds and 4 git commands to generate.