comparison Core/Endianness.h @ 2448:862d943115f9

working on linux standard base
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jan 2018 18:04:11 +0100
parents 878b59270859
children 98a04e75f15e
comparison
equal deleted inserted replaced
2447:878b59270859 2448:862d943115f9
36 36
37 /******************************************************************** 37 /********************************************************************
38 ** LINUX-LIKE ARCHITECTURES 38 ** LINUX-LIKE ARCHITECTURES
39 ********************************************************************/ 39 ********************************************************************/
40 40
41 #if defined(__linux__) || defined(__EMSCRIPTEN__) 41 #if defined(__LSB_VERSION__)
42 // Linux Standard Base (LSB) does not come with be16toh, be32toh, and
43 // be64toh
44 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0
45 # include <endian.h>
46 #elif defined(__linux__) || defined(__EMSCRIPTEN__)
42 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 47 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
43 # include <endian.h> 48 # include <endian.h>
44 #endif 49 #endif
45 50
46 51
153 static_cast<uint64_t>(p[5]) << 16 | 158 static_cast<uint64_t>(p[5]) << 16 |
154 static_cast<uint64_t>(p[6]) << 8 | 159 static_cast<uint64_t>(p[6]) << 8 |
155 static_cast<uint64_t>(p[7])); 160 static_cast<uint64_t>(p[7]));
156 } 161 }
157 162
163 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
164 # if __BYTE_ORDER == __LITTLE_ENDIAN
165 # define be16toh(x) __orthanc_bswap16(x)
166 # define be32toh(x) __orthanc_bswap32(x)
167 # define be64toh(x) __orthanc_bswap64(x)
168 # define htobe16(x) __orthanc_bswap16(x)
169 # define htobe32(x) __orthanc_bswap32(x)
170 # define htobe64(x) __orthanc_bswap64(x)
171 # define htole16(x) x
172 # define htole32(x) x
173 # define htole64(x) x
174 # define le16toh(x) x
175 # define le32toh(x) x
176 # define le64toh(x) x
177 # elif __BYTE_ORDER == __BIG_ENDIAN
178 # define be16toh(x) x
179 # define be32toh(x) x
180 # define be64toh(x) x
181 # define htobe16(x) x
182 # define htobe32(x) x
183 # define htobe64(x) x
184 # define htole16(x) __orthanc_bswap16(x)
185 # define htole32(x) __orthanc_bswap32(x)
186 # define htole64(x) __orthanc_bswap64(x)
187 # define le16toh(x) __orthanc_bswap16(x)
188 # define le32toh(x) __orthanc_bswap32(x)
189 # define le64toh(x) __orthanc_bswap64(x)
190 # else
191 # error Please support your platform here
192 # endif
193 #else
194 # error Please support your platform here
158 #endif 195 #endif
196
197 #endif