LibreOffice: osl/endian.h Source File

LibreOffice LibreOffice 5.1 SDK C/C++ API Reference

endian.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #ifndef INCLUDED_OSL_ENDIAN_H
21 #define INCLUDED_OSL_ENDIAN_H
22
23 #include <sal/types.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
31 #ifdef _WIN32
32 # if defined(_M_IX86)
33 # define _LITTLE_ENDIAN
34 # elif defined(_M_AMD64)
35 # define _LITTLE_ENDIAN
36 # elif defined(_M_MRX000)
37 # define _LITTLE_ENDIAN
38 # elif defined(_M_ALPHA)
39 # define _LITTLE_ENDIAN
40 # elif defined(_M_PPC)
41 # define _LITTLE_ENDIAN
42 # endif
43 #endif
44
45 #ifdef LINUX
46 # include <endian.h>
47 # if __BYTE_ORDER == __LITTLE_ENDIAN
48 # ifndef _LITTLE_ENDIAN
49 # define _LITTLE_ENDIAN
50 # endif
51 # elif __BYTE_ORDER == __BIG_ENDIAN
52 # ifndef _BIG_ENDIAN
53 # define _BIG_ENDIAN
54 # endif
55 # endif
56 #endif
57
58 #ifdef ANDROID
59 # include <endian.h>
60 # if __BYTE_ORDER == __LITTLE_ENDIAN
61 # ifndef _LITTLE_ENDIAN
62 # define _LITTLE_ENDIAN
63 # endif
64 # elif __BYTE_ORDER == __BIG_ENDIAN
65 # ifndef _BIG_ENDIAN
66 # define _BIG_ENDIAN
67 # endif
68 # endif
69 #endif
70
71 #ifdef EMSCRIPTEN
72 # include <endian.h>
73 # ifndef _LITTLE_ENDIAN
74 # define _LITTLE_ENDIAN
75 # endif
76 #endif
77
78 #ifdef NETBSD
79 # include <machine/endian.h>
80 # if BYTE_ORDER == LITTLE_ENDIAN
81 # undef _BIG_ENDIAN
82 # elif BYTE_ORDER == BIG_ENDIAN
83 # undef _LITTLE_ENDIAN
84 # endif
85 #endif
86
87 #ifdef FREEBSD
88 # include <sys/param.h>
89 # include <machine/endian.h>
90 #endif
91
92 #ifdef AIX
93 # include <sys/machine.h>
94 # if BYTE_ORDER == LITTLE_ENDIAN
95 # ifndef _LITTLE_ENDIAN
96 # define _LITTLE_ENDIAN
97 # endif
98 # elif BYTE_ORDER == BIG_ENDIAN
99 # ifndef _BIG_ENDIAN
100 # define _BIG_ENDIAN
101 # endif
102 # endif
103 #endif
104
105 #ifdef SOLARIS
106 # include <sys/isa_defs.h>
107 #endif
108
109 #ifdef MACOSX
110 # include <machine/endian.h>
111 # if BYTE_ORDER == LITTLE_ENDIAN
112 # ifndef _LITTLE_ENDIAN
113 # define _LITTLE_ENDIAN
114 # endif
115 # elif BYTE_ORDER == BIG_ENDIAN
116 # ifndef _BIG_ENDIAN
117 # define _BIG_ENDIAN
118 # endif
119 # endif
120 #endif
121
122 #ifdef IOS
123 # include <machine/endian.h>
124 # if BYTE_ORDER == LITTLE_ENDIAN
125 # ifndef _LITTLE_ENDIAN
126 # define _LITTLE_ENDIAN
127 # endif
128 # elif BYTE_ORDER == BIG_ENDIAN
129 # ifndef _BIG_ENDIAN
130 # define _BIG_ENDIAN
131 # endif
132 # endif
133 #endif
134
137 #if !defined(_WIN32) && \
138 !defined(LINUX) && !defined(NETBSD) && \
139 !defined(AIX) && !defined(OPENBSD) && \
140 !defined(SOLARIS) && !defined(MACOSX) && !defined(FREEBSD) && \
141 !defined(DRAGONFLY) && \
142 !defined(IOS) && !defined(ANDROID) && \
143 !defined(EMSCRIPTEN)
144 # error "Target platform not specified !"
145 #endif
146
147
150 #if defined _LITTLE_ENDIAN
151 # define OSL_LITENDIAN
152 #elif defined _BIG_ENDIAN
153 # define OSL_BIGENDIAN
154 #else
155 # error undetermined endianness
156 #endif
157
158
161 #ifndef OSL_MAKEBYTE
162 # define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
163 #endif
164 #ifndef OSL_LONIBBLE
165 # define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
166 #endif
167 #ifndef OSL_HINIBBLE
168 # define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
169 #endif
170
171 #ifndef OSL_MAKEWORD
172 # define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)))
173 #endif
174 #ifndef OSL_LOBYTE
175 # define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
176 #endif
177 #ifndef OSL_HIBYTE
178 # define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
179 #endif
180
181 #ifndef OSL_MAKEDWORD
182 # define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
183 #endif
184 #ifndef OSL_LOWORD
185 # define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
186 #endif
187 #ifndef OSL_HIWORD
188 # define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
189 #endif
190
191
194 #ifdef OSL_BIGENDIAN
195 #ifndef OSL_NETWORD
196 # define OSL_NETWORD(w) (sal_uInt16)(w)
197 #endif
198 #ifndef OSL_NETDWORD
199 # define OSL_NETDWORD(d) (sal_uInt32)(d)
200 #endif
201 #else /* OSL_LITENDIAN */
202 #ifndef OSL_NETWORD
203 # define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
204 #endif
205 #ifndef OSL_NETDWORD
206 # define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
207 #endif
208 #endif /* OSL_BIGENDIAN */
209
210
213 #ifndef OSL_SWAPWORD
214 # define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
215 #endif
216 #ifndef OSL_SWAPDWORD
217 # define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
218 #endif
219
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif // INCLUDED_OSL_ENDIAN_H
226
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
endian.h
types.h