LibreOffice
LibreOffice 6.0 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 
32 #if defined _WIN32
33 # if defined _M_ALPHA || defined _M_AMD64 || defined _M_IX86 \
34  || defined _M_MRX000 || defined _M_PPC
35 # define OSL_LITENDIAN
36 # endif
37 #elif defined ANDROID || defined LINUX
38 # include <endian.h>
39 # if __BYTE_ORDER == __LITTLE_ENDIAN
40 # define OSL_LITENDIAN
41 # elif __BYTE_ORDER == __BIG_ENDIAN
42 # define OSL_BIGENDIAN
43 # endif
44 #elif defined IOS || defined MACOSX || defined NETBSD
45 # include <machine/endian.h>
46 # if BYTE_ORDER == LITTLE_ENDIAN
47 # define OSL_LITENDIAN
48 # elif BYTE_ORDER == BIG_ENDIAN
49 # define OSL_BIGENDIAN
50 # endif
51 #elif defined FREEBSD
52 # include <sys/param.h>
53 # include <machine/endian.h>
54 # if defined _LITTLE_ENDIAN
55 # define OSL_LITENDIAN
56 # elif defined _BIG_ENDIAN
57 # define OSL_BIGENDIAN
58 # endif
59 #elif defined AIX
60 # include <sys/machine.h>
61 # if BYTE_ORDER == LITTLE_ENDIAN
62 # define OSL_LITENDIAN
63 # elif BYTE_ORDER == BIG_ENDIAN
64 # define OSL_BIGENDIAN
65 # endif
66 #elif defined __sun
67 # include <sys/isa_defs.h>
68 # if defined _LITTLE_ENDIAN
69 # define OSL_LITENDIAN
70 # elif defined _BIG_ENDIAN
71 # define OSL_BIGENDIAN
72 # endif
73 #else
74 # error "Target platform not specified !"
75 #endif
76 #if defined OSL_LITENDIAN == defined OSL_BIGENDIAN
77 # error undetermined endianness
78 #endif
79 
80 
83 #ifndef OSL_MAKEBYTE
84 # define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
85 #endif
86 #ifndef OSL_LONIBBLE
87 # define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
88 #endif
89 #ifndef OSL_HINIBBLE
90 # define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
91 #endif
92 
93 #ifndef OSL_MAKEWORD
94 # define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)))
95 #endif
96 #ifndef OSL_LOBYTE
97 # define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
98 #endif
99 #ifndef OSL_HIBYTE
100 # define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
101 #endif
102 
103 #ifndef OSL_MAKEDWORD
104 # define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
105 #endif
106 #ifndef OSL_LOWORD
107 # define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
108 #endif
109 #ifndef OSL_HIWORD
110 # define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
111 #endif
112 
113 
116 #ifdef OSL_BIGENDIAN
117 #ifndef OSL_NETWORD
118 # define OSL_NETWORD(w) (sal_uInt16)(w)
119 #endif
120 #ifndef OSL_NETDWORD
121 # define OSL_NETDWORD(d) (sal_uInt32)(d)
122 #endif
123 #else /* OSL_LITENDIAN */
124 #ifndef OSL_NETWORD
125 # define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
126 #endif
127 #ifndef OSL_NETDWORD
128 # define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
129 #endif
130 #endif /* OSL_BIGENDIAN */
131 
132 
135 #ifndef OSL_SWAPWORD
136 # define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
137 #endif
138 #ifndef OSL_SWAPDWORD
139 # define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
140 #endif
141 
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif // INCLUDED_OSL_ENDIAN_H
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */