Skip to content

Commit 851eba2

Browse files
committed
Improve support for different Windows SDK versions
1 parent d5cb565 commit 851eba2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

php_crc_fast.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@ extern "C" {
1919

2020
// Define htonll/ntohll for platforms that don't provide them
2121
#if defined(_WIN32) || defined(_WIN64)
22-
// Windows doesn't provide htonll/ntohll, so we define them here
23-
// Windows is always little-endian on x86/x64/ARM
24-
#ifndef htonll
25-
inline uint64_t htonll(uint64_t x) {
26-
return (((uint64_t)htonl((uint32_t)(x & 0xFFFFFFFF))) << 32) | htonl((uint32_t)(x >> 32));
27-
}
28-
inline uint64_t ntohll(uint64_t x) {
29-
return (((uint64_t)ntohl((uint32_t)(x & 0xFFFFFFFF))) << 32) | ntohl((uint32_t)(x >> 32));
30-
}
22+
// Windows SDK 10.0.26100.0+ provides htonll/ntohll in winsock2.h
23+
// For older SDK versions, we need to define them ourselves
24+
#include <winsock2.h>
25+
26+
// Check if we're using an older Windows SDK that doesn't have these functions
27+
// The functions were added in Windows SDK 10.0.26100.0
28+
#if !defined(NTDDI_WIN10_NI) || NTDDI_VERSION < NTDDI_WIN10_NI
29+
#ifndef htonll
30+
inline uint64_t htonll(uint64_t x) {
31+
return (((uint64_t)htonl((uint32_t)(x & 0xFFFFFFFF))) << 32) | htonl((uint32_t)(x >> 32));
32+
}
33+
#endif
34+
#ifndef ntohll
35+
inline uint64_t ntohll(uint64_t x) {
36+
return (((uint64_t)ntohl((uint32_t)(x & 0xFFFFFFFF))) << 32) | ntohl((uint32_t)(x >> 32));
37+
}
38+
#endif
3139
#endif
3240
#else
3341
// Unix-like platforms

0 commit comments

Comments
 (0)