File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
* The handling of float and double types was rewritten to fix compiler errors
4
4
and to eliminate the use of volatile.
5
+ * Improved endian preprocessor check if ` MMDB_LITTLE_ENDIAN ` is not set.
5
6
6
7
## 1.12.2 - 2025-01-10
7
8
Original file line number Diff line number Diff line change @@ -12,6 +12,14 @@ extern "C" {
12
12
#include <stdio.h>
13
13
#include <sys/types.h>
14
14
15
+ #ifdef __has_include
16
+ #if __has_include (< endian .h > )
17
+ #include <endian.h>
18
+ #elif __has_include (< sys /endian .h > )
19
+ #include <sys/endian.h>
20
+ #endif
21
+ #endif
22
+
15
23
#ifdef _WIN32
16
24
#include <winsock2.h>
17
25
#include <ws2tcpip.h>
@@ -28,6 +36,17 @@ extern "C" {
28
36
#include <sys/socket.h>
29
37
#endif
30
38
39
+ #if !defined(MMDB_LITTLE_ENDIAN )
40
+ #if defined(__BYTE_ORDER__ ) && defined(__ORDER_LITTLE_ENDIAN__ )
41
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
42
+ #define MMDB_LITTLE_ENDIAN 1
43
+ #endif
44
+ #elif defined(_WIN32 ) || defined(_WIN64 )
45
+ // We assume modern Windows targets are little endian
46
+ #define MMDB_LITTLE_ENDIAN 1
47
+ #endif
48
+ #endif
49
+
31
50
#define MMDB_DATA_TYPE_EXTENDED (0)
32
51
#define MMDB_DATA_TYPE_POINTER (1)
33
52
#define MMDB_DATA_TYPE_UTF8_STRING (2)
Original file line number Diff line number Diff line change @@ -1803,9 +1803,7 @@ static float get_ieee754_float(const uint8_t *restrict p) {
1803
1803
1804
1804
memcpy (& i , p , sizeof (uint32_t ));
1805
1805
1806
- /* Windows builds don't use autoconf but we can assume they're all
1807
- * little-endian. */
1808
- #if MMDB_LITTLE_ENDIAN || _WIN32
1806
+ #if MMDB_LITTLE_ENDIAN
1809
1807
i = bswap32 (i );
1810
1808
#endif
1811
1809
@@ -1820,7 +1818,7 @@ static double get_ieee754_double(const uint8_t *restrict p) {
1820
1818
1821
1819
memcpy (& i , p , sizeof (uint64_t ));
1822
1820
1823
- #if MMDB_LITTLE_ENDIAN || _WIN32
1821
+ #if MMDB_LITTLE_ENDIAN
1824
1822
i = bswap64 (i );
1825
1823
#endif
1826
1824
You can’t perform that action at this time.
0 commit comments