bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / osl / endian.h
blob43d0162b55df3639ee5cf73d3122f9447c3579f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OSL_ENDIAN_H
21 #define INCLUDED_OSL_ENDIAN_H
23 #include "sal/types.h"
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
29 /** Define the platform byte order as OSL_BIGENDIAN or OSL_LITENDIAN.
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 || defined HAIKU
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
81 /** Define macros for byte order manipulation.
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
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
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
114 /** Define macros for swapping between host and network byte order.
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 */
133 /** Define macros for swapping between byte orders.
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
143 #ifdef __cplusplus
145 #endif
147 #endif // INCLUDED_OSL_ENDIAN_H
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */