annotate Core/Endianness.h @ 3961:11aae2efff36 c-get

closing c-get
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 May 2020 18:38:09 +0200
parents 94f4a18a79cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 /********************************************************************
2407
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
38 ** LINUX-LIKE ARCHITECTURES
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
2448
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
41 #if defined(__LSB_VERSION__)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
42 // Linux Standard Base (LSB) does not come with be16toh, be32toh, and
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
43 // be64toh
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
44 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
45 # include <endian.h>
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
46 #elif defined(__linux__) || defined(__EMSCRIPTEN__)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
47 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 # include <endian.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ** WINDOWS ARCHITECTURES
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 **
1950
533ff46e944b return a single raw frame from DICOM videos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1939
diff changeset
55 ** On Windows x86, "host" will always be little-endian ("le").
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #if defined(_WIN32)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 # if defined(_MSC_VER)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
60 // Visual Studio - http://msdn.microsoft.com/en-us/library/a3140177.aspx
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
61 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 # define be16toh(x) _byteswap_ushort(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 # define be32toh(x) _byteswap_ulong(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 # define be64toh(x) _byteswap_uint64(x)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
65 # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
66 // MinGW >= 4.3 - Use builtin intrinsic for byte swapping
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
67 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 # define be16toh(x) __builtin_bswap16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 # define be32toh(x) __builtin_bswap32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 # define be64toh(x) __builtin_bswap64(x)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
71 # else
2546
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2459
diff changeset
72 // MinGW <= 4.2, we must manually implement the byte swapping (*)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
73 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
74 # define be16toh(x) __orthanc_bswap16(x)
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
75 # define be32toh(x) __orthanc_bswap32(x)
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
76 # define be64toh(x) __orthanc_bswap64(x)
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 # endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 # define htobe16(x) be16toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 # define htobe32(x) be32toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 # define htobe64(x) be64toh(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 # define htole16(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 # define htole32(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 # define htole64(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 # define le16toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 # define le32toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 # define le64toh(x) x
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 /********************************************************************
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ** FREEBSD ARCHITECTURES
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
98 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 # include <arpa/inet.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 #endif
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 /********************************************************************
2459
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
104 ** OPENBSD ARCHITECTURES
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
105 ********************************************************************/
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
106
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
107 #if defined(__OpenBSD__)
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
108 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
109 # include <endian.h>
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
110 #endif
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
111
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
112
98a04e75f15e endianness in openbsd
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2448
diff changeset
113 /********************************************************************
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ** APPLE ARCHITECTURES (including OS X)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ********************************************************************/
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #if defined(__APPLE__)
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
118 # define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
1938
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 # include <libkern/OSByteOrder.h>
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 # define be16toh(x) OSSwapBigToHostInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 # define be32toh(x) OSSwapBigToHostInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 # define be64toh(x) OSSwapBigToHostInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 # define htobe16(x) OSSwapHostToBigInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 # define htobe32(x) OSSwapHostToBigInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 # define htobe64(x) OSSwapHostToBigInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 # define htole16(x) OSSwapHostToLittleInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 # define htole32(x) OSSwapHostToLittleInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 # define htole64(x) OSSwapHostToLittleInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 # define le16toh(x) OSSwapLittleToHostInt16(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 # define le32toh(x) OSSwapLittleToHostInt32(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 # define le64toh(x) OSSwapLittleToHostInt64(x)
48ad54f7b21f endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 #endif
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
136
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
137
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
138 /********************************************************************
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
139 ** PORTABLE (BUT SLOW) IMPLEMENTATION OF BYTE-SWAPPING
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
140 ********************************************************************/
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
141
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
142 #if ORTHANC_HAS_BUILTIN_BYTE_SWAP != 1
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
143
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
144 #include <stdint.h>
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
145
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
146 static inline uint16_t __orthanc_bswap16(uint16_t a)
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
147 {
2807
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
148 /**
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
149 * Note that an alternative implementation was included in Orthanc
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
150 * 1.4.0 and 1.4.1:
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
151 *
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
152 * # hg log -p -r 2706
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
153 *
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
154 * This alternative implementation only hid an underlying problem
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
155 * with pointer alignment on some architectures, and was thus
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
156 * reverted. Check out issue #99:
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
157 * https://bitbucket.org/sjodogne/orthanc/issues/99
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
158 **/
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2707
diff changeset
159 return (a << 8) | (a >> 8);
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
160 }
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
161
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
162 static inline uint32_t __orthanc_bswap32(uint32_t a)
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
163 {
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
164 const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
165 return (static_cast<uint32_t>(p[0]) << 24 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
166 static_cast<uint32_t>(p[1]) << 16 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
167 static_cast<uint32_t>(p[2]) << 8 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
168 static_cast<uint32_t>(p[3]));
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
169 }
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
170
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
171 static inline uint64_t __orthanc_bswap64(uint64_t a)
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
172 {
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
173 const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
174 return (static_cast<uint64_t>(p[0]) << 56 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
175 static_cast<uint64_t>(p[1]) << 48 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
176 static_cast<uint64_t>(p[2]) << 40 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
177 static_cast<uint64_t>(p[3]) << 32 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
178 static_cast<uint64_t>(p[4]) << 24 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
179 static_cast<uint64_t>(p[5]) << 16 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
180 static_cast<uint64_t>(p[6]) << 8 |
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
181 static_cast<uint64_t>(p[7]));
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
182 }
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
183
2546
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2459
diff changeset
184 #if defined(_WIN32)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2459
diff changeset
185 // Implemented above (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2459
diff changeset
186 #elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
2448
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
187 # if __BYTE_ORDER == __LITTLE_ENDIAN
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
188 # define be16toh(x) __orthanc_bswap16(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
189 # define be32toh(x) __orthanc_bswap32(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
190 # define be64toh(x) __orthanc_bswap64(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
191 # define htobe16(x) __orthanc_bswap16(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
192 # define htobe32(x) __orthanc_bswap32(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
193 # define htobe64(x) __orthanc_bswap64(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
194 # define htole16(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
195 # define htole32(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
196 # define htole64(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
197 # define le16toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
198 # define le32toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
199 # define le64toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
200 # elif __BYTE_ORDER == __BIG_ENDIAN
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
201 # define be16toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
202 # define be32toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
203 # define be64toh(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
204 # define htobe16(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
205 # define htobe32(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
206 # define htobe64(x) x
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
207 # define htole16(x) __orthanc_bswap16(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
208 # define htole32(x) __orthanc_bswap32(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
209 # define htole64(x) __orthanc_bswap64(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
210 # define le16toh(x) __orthanc_bswap16(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
211 # define le32toh(x) __orthanc_bswap32(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
212 # define le64toh(x) __orthanc_bswap64(x)
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
213 # else
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
214 # error Please support your platform here
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
215 # endif
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
216 #else
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
217 # error Please support your platform here
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1950
diff changeset
218 #endif
2448
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
219
862d943115f9 working on linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
220 #endif