mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fix build when targeting Windows 7 as platform. (#1869)
* Fix build when targeting Windows 7 as platform. This change makes more of the code introduced in https://github.com/yhirose/cpp-httplib/pull/1775 conditional on feature macros. `CreateFile2`, `CreateFileMappingFromApp` and `MapViewOfFileFromApp` are available only starting from Windows 8. * https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 * https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingfromapp * https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffilefromapp * Update feature macros used and use `GetFileSizeEx` conditionally.
This commit is contained in:
parent
8cd0ed0509
commit
c8bcaf8a91
1 changed files with 15 additions and 2 deletions
17
httplib.h
17
httplib.h
|
@ -2824,16 +2824,29 @@ inline bool mmap::open(const char *path) {
|
|||
wpath += path[i];
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,
|
||||
OPEN_EXISTING, NULL);
|
||||
#else
|
||||
hFile_ = ::CreateFileW(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#endif
|
||||
|
||||
if (hFile_ == INVALID_HANDLE_VALUE) { return false; }
|
||||
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM | WINAPI_PARTITION_GAMES)
|
||||
LARGE_INTEGER size{};
|
||||
if (!::GetFileSizeEx(hFile_, &size)) { return false; }
|
||||
size_ = static_cast<size_t>(size.QuadPart);
|
||||
#else
|
||||
DWORD sizeHigh;
|
||||
DWORD sizeLow;
|
||||
sizeLow = ::GetFileSize(hFile_, &sizeHigh);
|
||||
if (sizeLow == INVALID_FILE_SIZE) { return false; }
|
||||
size_ = (static_cast<size_t>(sizeHigh) << (sizeof(DWORD) * 8)) | sizeLow;
|
||||
#endif
|
||||
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
hMapping_ =
|
||||
::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL);
|
||||
#else
|
||||
|
@ -2847,7 +2860,7 @@ inline bool mmap::open(const char *path) {
|
|||
return false;
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||
addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);
|
||||
#else
|
||||
addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);
|
||||
|
|
Loading…
Reference in a new issue