1938
|
1 /**
|
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
|
5 *
|
|
6 * This program is free software: you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU General Public License as
|
|
8 * published by the Free Software Foundation, either version 3 of the
|
|
9 * License, or (at your option) any later version.
|
|
10 *
|
|
11 * In addition, as a special exception, the copyright holders of this
|
|
12 * program give permission to link the code of its release with the
|
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
|
|
14 * that use the same license as the "OpenSSL" library), and distribute
|
|
15 * the linked executables. You must obey the GNU General Public License
|
|
16 * in all respects for all of the code used other than "OpenSSL". If you
|
|
17 * modify file(s) with this exception, you may extend this exception to
|
|
18 * your version of the file(s), but you are not obligated to do so. If
|
|
19 * you do not wish to do so, delete this exception statement from your
|
|
20 * version. If you delete this exception statement from all source files
|
|
21 * in the program, then also delete it here.
|
|
22 *
|
|
23 * This program is distributed in the hope that it will be useful, but
|
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
26 * General Public License for more details.
|
|
27 *
|
|
28 * You should have received a copy of the GNU General Public License
|
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30 **/
|
|
31
|
|
32
|
|
33 #pragma once
|
|
34
|
|
35
|
|
36 /********************************************************************
|
|
37 ** LINUX ARCHITECTURES
|
|
38 ********************************************************************/
|
|
39
|
|
40 #if defined(__linux)
|
|
41 # include <endian.h>
|
|
42 #endif
|
|
43
|
|
44
|
|
45 /********************************************************************
|
|
46 ** WINDOWS ARCHITECTURES
|
|
47 **
|
|
48 ** On Windows, "host" will always be little-endian ("le").
|
|
49 ********************************************************************/
|
|
50
|
|
51 #if defined(_WIN32)
|
|
52 #include <winsock2.h>
|
|
53 # if defined(_MSC_VER)
|
|
54 // http://msdn.microsoft.com/en-us/library/a3140177.aspx
|
|
55 # define be16toh(x) _byteswap_ushort(x)
|
|
56 # define be32toh(x) _byteswap_ulong(x)
|
|
57 # define be64toh(x) _byteswap_uint64(x)
|
|
58 # else // MinGW
|
|
59 # define be16toh(x) __builtin_bswap16(x)
|
|
60 # define be32toh(x) __builtin_bswap32(x)
|
|
61 # define be64toh(x) __builtin_bswap64(x)
|
|
62 # endif
|
|
63
|
|
64 # define htobe16(x) be16toh(x)
|
|
65 # define htobe32(x) be32toh(x)
|
|
66 # define htobe64(x) be64toh(x)
|
|
67
|
|
68 # define htole16(x) x
|
|
69 # define htole32(x) x
|
|
70 # define htole64(x) x
|
|
71
|
|
72 # define le16toh(x) x
|
|
73 # define le32toh(x) x
|
|
74 # define le64toh(x) x
|
|
75 #endif
|
|
76
|
|
77
|
|
78 /********************************************************************
|
|
79 ** FREEBSD ARCHITECTURES
|
|
80 ********************************************************************/
|
|
81
|
|
82 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
83 # include <arpa/inet.h>
|
|
84 #endif
|
|
85
|
|
86
|
|
87 /********************************************************************
|
|
88 ** APPLE ARCHITECTURES (including OS X)
|
|
89 ********************************************************************/
|
|
90
|
|
91 #if defined(__APPLE__)
|
|
92 # include <libkern/OSByteOrder.h>
|
|
93 # define be16toh(x) OSSwapBigToHostInt16(x)
|
|
94 # define be32toh(x) OSSwapBigToHostInt32(x)
|
|
95 # define be64toh(x) OSSwapBigToHostInt64(x)
|
|
96
|
|
97 # define htobe16(x) OSSwapHostToBigInt16(x)
|
|
98 # define htobe32(x) OSSwapHostToBigInt32(x)
|
|
99 # define htobe64(x) OSSwapHostToBigInt64(x)
|
|
100
|
|
101 # define htole16(x) OSSwapHostToLittleInt16(x)
|
|
102 # define htole32(x) OSSwapHostToLittleInt32(x)
|
|
103 # define htole64(x) OSSwapHostToLittleInt64(x)
|
|
104
|
|
105 # define le16toh(x) OSSwapLittleToHostInt16(x)
|
|
106 # define le32toh(x) OSSwapLittleToHostInt32(x)
|
|
107 # define le64toh(x) OSSwapLittleToHostInt64(x)
|
|
108 #endif
|