1
+ /*
2
+ ** Command & Conquer Generals Zero Hour(tm)
3
+ ** Copyright 2025 TheSuperHackers
4
+ **
5
+ ** This program is free software: you can redistribute it and/or modify
6
+ ** it under the terms of the GNU General Public License as published by
7
+ ** the Free Software Foundation, either version 3 of the License, or
8
+ ** (at your option) any later version.
9
+ **
10
+ ** This program is distributed in the hope that it will be useful,
11
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ ** GNU General Public License for more details.
14
+ **
15
+ ** You should have received a copy of the GNU General Public License
16
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ // This file contains macros to help with endian conversions between different endian systems.
20
+ #pragma once
21
+
22
+ #if defined(__linux__ ) || defined(__CYGWIN__ )
23
+ #include <endian.h>
24
+
25
+ #elif defined(__APPLE__ )
26
+ #include <libkern/OSByteOrder.h>
27
+
28
+ #define htobe16 (x ) OSSwapHostToBigInt16(x)
29
+ #define htole16 (x ) OSSwapHostToLittleInt16(x)
30
+ #define be16toh (x ) OSSwapBigToHostInt16(x)
31
+ #define le16toh (x ) OSSwapLittleToHostInt16(x)
32
+
33
+ #define htobe32 (x ) OSSwapHostToBigInt32(x)
34
+ #define htole32 (x ) OSSwapHostToLittleInt32(x)
35
+ #define be32toh (x ) OSSwapBigToHostInt32(x)
36
+ #define le32toh (x ) OSSwapLittleToHostInt32(x)
37
+
38
+ #define htobe64 (x ) OSSwapHostToBigInt64(x)
39
+ #define htole64 (x ) OSSwapHostToLittleInt64(x)
40
+ #define be64toh (x ) OSSwapBigToHostInt64(x)
41
+ #define le64toh (x ) OSSwapLittleToHostInt64(x)
42
+
43
+ #elif defined(__OpenBSD__ )
44
+ #include <sys/endian.h>
45
+
46
+ #elif defined(__NetBSD__ ) || defined(__FreeBSD__ ) || defined(__DragonFly__ )
47
+ #include <sys/endian.h>
48
+
49
+ #define be16toh (x ) betoh16(x)
50
+ #define le16toh (x ) letoh16(x)
51
+
52
+ #define be32toh (x ) betoh32(x)
53
+ #define le32toh (x ) letoh32(x)
54
+
55
+ #define be64toh (x ) betoh64(x)
56
+ #define le64toh (x ) letoh64(x)
57
+
58
+ #elif defined(_WIN32 ) || defined(_WIN64 )
59
+ #if defined (_MSC_VER )
60
+ #include <intrin.h>
61
+ #else
62
+ #include <stdlib.h>
63
+ #endif // _MSC_VER
64
+
65
+ #define htobe16 (x ) _byteswap_ushort(x)
66
+ #define htole16 (x ) (x)
67
+ #define be16toh (x ) _byteswap_ushort(x)
68
+ #define le16toh (x ) (x)
69
+
70
+ #define htobe32 (x ) _byteswap_ulong(x)
71
+ #define htole32 (x ) (x)
72
+ #define be32toh (x ) _byteswap_ulong(x)
73
+ #define le32toh (x ) (x)
74
+
75
+ #define htobe64 (x ) _byteswap_uint64(x)
76
+ #define htole64 (x ) (x)
77
+ #define be64toh (x ) _byteswap_uint64(x)
78
+ #define le64toh (x ) (x)
79
+
80
+ #else
81
+ #error platform not supported
82
+ #endif
0 commit comments