LibreOffice
LibreOffice 7.4 SDK C/C++ API Reference
osl
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
/*
21
* This file is part of LibreOffice published API.
22
*/
23
24
#ifndef INCLUDED_OSL_ENDIAN_H
25
#define INCLUDED_OSL_ENDIAN_H
26
27
#include "
sal/types.h
"
28
29
#ifdef __cplusplus
30
extern
"C"
{
31
#endif
32
36
#if defined _WIN32
37
# if defined _M_ALPHA || defined _M_AMD64 || defined _M_IX86 \
38
|| defined _M_MRX000 || defined _M_PPC || defined _M_ARM64
39
# define OSL_LITENDIAN
40
# endif
41
#elif defined ANDROID || defined LINUX || defined HAIKU
42
# include <
endian.h
>
43
# if __BYTE_ORDER == __LITTLE_ENDIAN
44
# define OSL_LITENDIAN
45
# elif __BYTE_ORDER == __BIG_ENDIAN
46
# define OSL_BIGENDIAN
47
# endif
48
#elif defined IOS || defined MACOSX || defined NETBSD
49
# include <machine/endian.h>
50
# if BYTE_ORDER == LITTLE_ENDIAN
51
# define OSL_LITENDIAN
52
# elif BYTE_ORDER == BIG_ENDIAN
53
# define OSL_BIGENDIAN
54
# endif
55
#elif defined FREEBSD
56
# include <sys/param.h>
57
# include <machine/endian.h>
58
# if defined _LITTLE_ENDIAN
59
# define OSL_LITENDIAN
60
# elif defined _BIG_ENDIAN
61
# define OSL_BIGENDIAN
62
# endif
63
#elif defined AIX
64
# include <sys/machine.h>
65
# if BYTE_ORDER == LITTLE_ENDIAN
66
# define OSL_LITENDIAN
67
# elif BYTE_ORDER == BIG_ENDIAN
68
# define OSL_BIGENDIAN
69
# endif
70
#elif defined __sun
71
# include <sys/isa_defs.h>
72
# if defined _LITTLE_ENDIAN
73
# define OSL_LITENDIAN
74
# elif defined _BIG_ENDIAN
75
# define OSL_BIGENDIAN
76
# endif
77
#elif defined EMSCRIPTEN
78
# define OSL_LITENDIAN
79
#else
80
# error "Target platform not specified !"
81
#endif
82
#if defined OSL_LITENDIAN == defined OSL_BIGENDIAN
83
# error undetermined endianness
84
#endif
85
86
89
#ifndef OSL_MAKEBYTE
90
# define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
91
#endif
92
#ifndef OSL_LONIBBLE
93
# define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
94
#endif
95
#ifndef OSL_HINIBBLE
96
# define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
97
#endif
98
99
#ifndef OSL_MAKEWORD
100
# define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)))
101
#endif
102
#ifndef OSL_LOBYTE
103
# define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
104
#endif
105
#ifndef OSL_HIBYTE
106
# define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
107
#endif
108
109
#ifndef OSL_MAKEDWORD
110
# define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
111
#endif
112
#ifndef OSL_LOWORD
113
# define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
114
#endif
115
#ifndef OSL_HIWORD
116
# define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
117
#endif
118
119
122
#ifdef OSL_BIGENDIAN
123
#ifndef OSL_NETWORD
124
# define OSL_NETWORD(w) (sal_uInt16)(w)
125
#endif
126
#ifndef OSL_NETDWORD
127
# define OSL_NETDWORD(d) (sal_uInt32)(d)
128
#endif
129
#else
/* OSL_LITENDIAN */
130
#ifndef OSL_NETWORD
131
# define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
132
#endif
133
#ifndef OSL_NETDWORD
134
# define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
135
#endif
136
#endif
/* OSL_BIGENDIAN */
137
138
141
#ifndef OSL_SWAPWORD
142
# define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
143
#endif
144
#ifndef OSL_SWAPDWORD
145
# define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
146
#endif
147
148
149
#ifdef __cplusplus
150
}
151
#endif
152
153
#endif
// INCLUDED_OSL_ENDIAN_H
154
155
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
types.h
endian.h
Generated by
1.9.1