1 #ifndef _BABELTRACE_ENDIAN_H
2 #define _BABELTRACE_ENDIAN_H
7 * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * endian.h compatibility layer.
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
31 #include <machine/endian.h>
32 #elif defined(__MINGW32__)
34 #define __BIG_ENDIAN 4321
36 #ifndef __LITTLE_ENDIAN
37 #define __LITTLE_ENDIAN 1234
41 #define __BYTE_ORDER __LITTLE_ENDIAN
44 #define LITTLE_ENDIAN __LITTLE_ENDIAN
45 #define BIG_ENDIAN __BIG_ENDIAN
46 #define PDP_ENDIAN __PDP_ENDIAN
47 #define BYTE_ORDER __BYTE_ORDER
52 * htobe/betoh are not defined for glibc < 2.9, so add them explicitly
53 * if they are missing.
56 /* Conversion interfaces. */
57 # include <byteswap.h>
59 # if __BYTE_ORDER == __LITTLE_ENDIAN
61 # define htobe16(x) __bswap_16(x)
64 # define htole16(x) (x)
67 # define be16toh(x) __bswap_16(x)
70 # define le16toh(x) (x)
74 # define htobe32(x) __bswap_32(x)
77 # define htole32(x) (x)
80 # define be32toh(x) __bswap_32(x)
83 # define le32toh(x) (x)
87 # define htobe64(x) __bswap_64(x)
90 # define htole64(x) (x)
93 # define be64toh(x) __bswap_64(x)
96 # define le64toh(x) (x)
99 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
101 # define htobe16(x) (x)
104 # define htole16(x) __bswap_16(x)
107 # define be16toh(x) (x)
110 # define le16toh(x) __bswap_16(x)
114 # define htobe32(x) (x)
117 # define htole32(x) __bswap_32(x)
120 # define be32toh(x) (x)
123 # define le32toh(x) __bswap_32(x)
127 # define htobe64(x) (x)
130 # define htole64(x) __bswap_64(x)
133 # define be64toh(x) (x)
136 # define le64toh(x) __bswap_64(x)
139 # endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
140 # endif /* __USE_BSD */
141 #endif /* else -- __FreeBSD__ */
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 */
151 #endif /* _BABELTRACE_ENDIAN_H */
This page took 0.033202 seconds and 4 git commands to generate.