LibreOffice
LibreOffice 24.8 SDK C/C++ API Reference
 
Loading...
Searching...
No Matches
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
30extern "C" {
31#endif
32
35
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 __sun
64# include <sys/isa_defs.h>
65# if defined _LITTLE_ENDIAN
66# define OSL_LITENDIAN
67# elif defined _BIG_ENDIAN
68# define OSL_BIGENDIAN
69# endif
70#elif defined EMSCRIPTEN
71# define OSL_LITENDIAN
72#else
73# error "Target platform not specified !"
74#endif
75#if defined OSL_LITENDIAN == defined OSL_BIGENDIAN
76# error undetermined endianness
77#endif
78
79
82#ifndef OSL_MAKEBYTE
83# define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
84#endif
85#ifndef OSL_LONIBBLE
86# define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
87#endif
88#ifndef OSL_HINIBBLE
89# define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
90#endif
91
92#ifndef OSL_MAKEWORD
93# define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8)))
94#endif
95#ifndef OSL_LOBYTE
96# define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
97#endif
98#ifndef OSL_HIBYTE
99# define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
100#endif
101
102#ifndef OSL_MAKEDWORD
103# define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
104#endif
105#ifndef OSL_LOWORD
106# define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
107#endif
108#ifndef OSL_HIWORD
109# define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
110#endif
111
112
115#ifdef OSL_BIGENDIAN
116#ifndef OSL_NETWORD
117# define OSL_NETWORD(w) (sal_uInt16)(w)
118#endif
119#ifndef OSL_NETDWORD
120# define OSL_NETDWORD(d) (sal_uInt32)(d)
121#endif
122#else /* OSL_LITENDIAN */
123#ifndef OSL_NETWORD
124# define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
125#endif
126#ifndef OSL_NETDWORD
127# define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
128#endif
129#endif /* OSL_BIGENDIAN */
130
131
134#ifndef OSL_SWAPWORD
135# define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
136#endif
137#ifndef OSL_SWAPDWORD
138# define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
139#endif
140
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif // INCLUDED_OSL_ENDIAN_H
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */