Commit | Line | Data |
---|---|---|
b1acd2b3 JD |
1 | #ifndef _BABELTRACE_ENDIAN_H |
2 | #define _BABELTRACE_ENDIAN_H | |
3 | ||
4 | /* | |
5 | * babeltrace/endian.h | |
6 | * | |
7 | * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * endian.h compatibility layer. | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
30 | #ifdef __FreeBSD__ | |
31 | #include <machine/endian.h> | |
32 | #elif defined(__MINGW32__) | |
33 | #ifndef __BIG_ENDIAN | |
34 | #define __BIG_ENDIAN 4321 | |
35 | #endif | |
36 | #ifndef __LITTLE_ENDIAN | |
37 | #define __LITTLE_ENDIAN 1234 | |
38 | #endif | |
39 | ||
40 | #ifndef __BYTE_ORDER | |
41 | #define __BYTE_ORDER __LITTLE_ENDIAN | |
42 | #endif | |
43 | ||
44 | #define LITTLE_ENDIAN __LITTLE_ENDIAN | |
45 | #define BIG_ENDIAN __BIG_ENDIAN | |
46 | #define PDP_ENDIAN __PDP_ENDIAN | |
47 | #define BYTE_ORDER __BYTE_ORDER | |
48 | #else | |
49 | #include <endian.h> | |
4a325d7e JD |
50 | |
51 | /* | |
52 | * htobe/betoh are not defined for glibc < 2.9, so add them explicitly | |
53 | * if they are missing. | |
54 | */ | |
55 | # ifdef __USE_BSD | |
56 | /* Conversion interfaces. */ | |
57 | # include <byteswap.h> | |
58 | ||
59 | # if __BYTE_ORDER == __LITTLE_ENDIAN | |
60 | # ifndef htobe16 | |
61 | # define htobe16(x) __bswap_16(x) | |
62 | # endif | |
63 | # ifndef htole16 | |
64 | # define htole16(x) (x) | |
65 | # endif | |
66 | # ifndef be16toh | |
67 | # define be16toh(x) __bswap_16(x) | |
68 | # endif | |
69 | # ifndef le16toh | |
70 | # define le16toh(x) (x) | |
71 | # endif | |
72 | ||
73 | # ifndef htobe32 | |
74 | # define htobe32(x) __bswap_32(x) | |
75 | # endif | |
76 | # ifndef htole32 | |
77 | # define htole32(x) (x) | |
78 | # endif | |
79 | # ifndef be32toh | |
80 | # define be32toh(x) __bswap_32(x) | |
81 | # endif | |
82 | # ifndef le32toh | |
83 | # define le32toh(x) (x) | |
84 | # endif | |
85 | ||
86 | # ifndef htobe64 | |
87 | # define htobe64(x) __bswap_64(x) | |
88 | # endif | |
89 | # ifndef htole64 | |
90 | # define htole64(x) (x) | |
91 | # endif | |
92 | # ifndef be64toh | |
93 | # define be64toh(x) __bswap_64(x) | |
94 | # endif | |
95 | # ifndef le64toh | |
96 | # define le64toh(x) (x) | |
97 | # endif | |
98 | ||
99 | # else /* __BYTE_ORDER == __LITTLE_ENDIAN */ | |
100 | # ifndef htobe16 | |
101 | # define htobe16(x) (x) | |
102 | # endif | |
103 | # ifndef htole16 | |
104 | # define htole16(x) __bswap_16(x) | |
105 | # endif | |
106 | # ifndef be16toh | |
107 | # define be16toh(x) (x) | |
108 | # endif | |
109 | # ifndef le16toh | |
110 | # define le16toh(x) __bswap_16(x) | |
111 | # endif | |
112 | ||
113 | # ifndef htobe32 | |
114 | # define htobe32(x) (x) | |
115 | # endif | |
116 | # ifndef htole32 | |
117 | # define htole32(x) __bswap_32(x) | |
118 | # endif | |
119 | # ifndef be32toh | |
120 | # define be32toh(x) (x) | |
121 | # endif | |
122 | # ifndef le32toh | |
123 | # define le32toh(x) __bswap_32(x) | |
124 | # endif | |
125 | ||
126 | # ifndef htobe64 | |
127 | # define htobe64(x) (x) | |
128 | # endif | |
129 | # ifndef htole64 | |
130 | # define htole64(x) __bswap_64(x) | |
131 | # endif | |
132 | # ifndef be64toh | |
133 | # define be64toh(x) (x) | |
134 | # endif | |
135 | # ifndef le64toh | |
136 | # define le64toh(x) __bswap_64(x) | |
137 | # endif | |
138 | ||
139 | # endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ | |
140 | # endif /* __USE_BSD */ | |
141 | #endif /* else -- __FreeBSD__ */ | |
b1acd2b3 JD |
142 | |
143 | #ifndef FLOAT_WORD_ORDER | |
144 | #ifdef __FLOAT_WORD_ORDER | |
145 | #define FLOAT_WORD_ORDER __FLOAT_WORD_ORDER | |
146 | #else /* __FLOAT_WORD_ORDER */ | |
147 | #define FLOAT_WORD_ORDER BYTE_ORDER | |
148 | #endif /* __FLOAT_WORD_ORDER */ | |
149 | #endif /* FLOAT_WORD_ORDER */ | |
150 | ||
151 | #endif /* _BABELTRACE_ENDIAN_H */ |