Update ooo320-m1
[ooovba.git] / sal / inc / osl / endian.h
blob44a085bc9bb36e370d76bc4d4cb9ca99c0eec073
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: endian.h,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _OSL_ENDIAN_H_
32 #define _OSL_ENDIAN_H_
34 #include <sal/types.h>
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
40 /** Determine the platform byte order as _BIG_ENDIAN, _LITTLE_ENDIAN, ...
42 #ifdef _WIN32
43 # if defined(_M_IX86)
44 # define _LITTLE_ENDIAN
45 # elif defined(_M_MRX000)
46 # define _LITTLE_ENDIAN
47 # elif defined(_M_ALPHA)
48 # define _LITTLE_ENDIAN
49 # elif defined(_M_PPC)
50 # define _LITTLE_ENDIAN
51 # endif
52 #endif
54 #ifdef LINUX
55 # include <endian.h>
56 # if __BYTE_ORDER == __LITTLE_ENDIAN
57 # ifndef _LITTLE_ENDIAN
58 # define _LITTLE_ENDIAN
59 # endif
60 # elif __BYTE_ORDER == __BIG_ENDIAN
61 # ifndef _BIG_ENDIAN
62 # define _BIG_ENDIAN
63 # endif
64 # elif __BYTE_ORDER == __PDP_ENDIAN
65 # define _PDP_ENDIAN
66 # endif
67 #endif
69 #ifdef NETBSD
70 # include <machine/endian.h>
71 # if BYTE_ORDER == LITTLE_ENDIAN
72 # define _LITTLE_ENDIAN
73 # elif BYTE_ORDER == BIG_ENDIAN
74 # define _BIG_ENDIAN
75 # elif BYTE_ORDER == PDP_ENDIAN
76 # define _PDP_ENDIAN
77 # endif
78 #endif
80 #ifdef FREEBSD
81 # include <sys/param.h>
82 # include <machine/endian.h>
83 #if __FreeBSD_version < 500000
84 # if BYTE_ORDER == LITTLE_ENDIAN
85 # define _LITTLE_ENDIAN
86 # elif BYTE_ORDER == BIG_ENDIAN
87 # define _BIG_ENDIAN
88 # elif BYTE_ORDER == PDP_ENDIAN
89 # define _PDP_ENDIAN
90 # endif
91 #endif
92 #endif
94 #ifdef SCO
95 # include <sys/types.h>
96 # include <sys/byteorder.h>
97 # if BYTE_ORDER == LITTLE_ENDIAN
98 # define _LITTLE_ENDIAN
99 # elif BYTE_ORDER == BIG_ENDIAN
100 # define _BIG_ENDIAN
101 # elif BYTE_ORDER == PDP_ENDIAN
102 # define _PDP_ENDIAN
103 # endif
104 #endif
106 #ifdef AIX
107 # include <sys/machine.h>
108 # if BYTE_ORDER == LITTLE_ENDIAN
109 # define _LITTLE_ENDIAN
110 # elif BYTE_ORDER == BIG_ENDIAN
111 # define _BIG_ENDIAN
112 # elif BYTE_ORDER == PDP_ENDIAN
113 # define _PDP_ENDIAN
114 # endif
115 #endif
117 #ifdef HPUX
118 # include <machine/param.h>
119 #endif
121 #ifdef IRIX
122 # include <sys/endian.h>
123 # if BYTE_ORDER == LITTLE_ENDIAN
124 # undef _BIG_ENDIAN
125 # undef _PDP_ENDIAN
126 # elif BYTE_ORDER == BIG_ENDIAN
127 # undef _LITTLE_ENDIAN
128 # undef _PDP_ENDIAN
129 # elif BYTE_ORDER == PDP_ENDIAN
130 # undef _LITTLE_ENDIAN
131 # undef _BIG_ENDIAN
132 # endif
133 #endif
135 #ifdef _WIN16
136 # define _LITTLE_ENDIAN
137 #endif
139 #ifdef OS2
140 # include <machine/endian.h>
141 #endif
143 #ifdef SOLARIS
144 # include <sys/isa_defs.h>
145 #endif
147 #ifdef MACOSX
148 # include <machine/endian.h>
149 # if BYTE_ORDER == LITTLE_ENDIAN
150 # ifndef _LITTLE_ENDIAN
151 # define _LITTLE_ENDIAN
152 # endif
153 # elif BYTE_ORDER == BIG_ENDIAN
154 # ifndef _BIG_ENDIAN
155 # define _BIG_ENDIAN
156 # endif
157 # elif BYTE_ORDER == PDP_ENDIAN
158 # ifndef _PDP_ENDIAN
159 # define _PDP_ENDIAN
160 # endif
161 # endif
162 #endif
164 /** Check supported platform.
166 #if !defined(_WIN32) && !defined(_WIN16) && !defined(OS2) && \
167 !defined(LINUX) && !defined(NETBSD) && !defined(SCO) && \
168 !defined(AIX) && !defined(HPUX) && \
169 !defined(SOLARIS) && !defined(IRIX) && \
170 !defined(MACOSX) && !defined(FREEBSD)
171 # error "Target platform not specified !"
172 #endif
175 /** Define the determined byte order as OSL_BIGENDIAN or OSL_LITENDIAN.
177 #if defined _LITTLE_ENDIAN
178 # define OSL_LITENDIAN
179 #elif defined _BIG_ENDIAN
180 # define OSL_BIGENDIAN
181 #else
182 # error undetermined endianess
183 #endif
186 /** Define macros for byte order manipulation.
188 #ifndef OSL_MAKEBYTE
189 # define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
190 #endif
191 #ifndef OSL_LONIBBLE
192 # define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
193 #endif
194 #ifndef OSL_HINIBBLE
195 # define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
196 #endif
198 #ifndef OSL_MAKEWORD
199 # define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8))
200 #endif
201 #ifndef OSL_LOBYTE
202 # define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
203 #endif
204 #ifndef OSL_HIBYTE
205 # define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
206 #endif
208 #ifndef OSL_MAKEDWORD
209 # define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
210 #endif
211 #ifndef OSL_LOWORD
212 # define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
213 #endif
214 #ifndef OSL_HIWORD
215 # define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
216 #endif
219 /** Define macros for swapping between host and network byte order.
221 #ifdef OSL_BIGENDIAN
222 #ifndef OSL_NETWORD
223 # define OSL_NETWORD(w) (sal_uInt16)(w)
224 #endif
225 #ifndef OSL_NETDWORD
226 # define OSL_NETDWORD(d) (sal_uInt32)(d)
227 #endif
228 #else /* OSL_LITENDIAN */
229 #ifndef OSL_NETWORD
230 # define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
231 #endif
232 #ifndef OSL_NETDWORD
233 # define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
234 #endif
235 #endif /* OSL_BIGENDIAN */
238 /** Define macros for swapping between byte orders.
240 #ifndef OSL_SWAPWORD
241 # define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
242 #endif
243 #ifndef OSL_SWAPDWORD
244 # define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
245 #endif
248 #ifdef __cplusplus
250 #endif
252 #endif /*_OSL_ENDIAN_H_ */