Skip to content

Commit

Permalink
Fix build when targeting Windows 7 as platform.
Browse files Browse the repository at this point in the history
This change makes more of the code introduced in
#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
  • Loading branch information
mol123 committed Jun 27, 2024
1 parent 388a8c0 commit 423b581
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2823,16 +2823,21 @@ inline bool mmap::open(const char *path) {
wpath += path[i];
}

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_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; }

LARGE_INTEGER size{};
if (!::GetFileSizeEx(hFile_, &size)) { return false; }
size_ = static_cast<size_t>(size.QuadPart);

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
hMapping_ =
::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_, NULL);
#else
Expand All @@ -2846,7 +2851,7 @@ inline bool mmap::open(const char *path) {
return false;
}

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);
#else
addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);
Expand Down

0 comments on commit 423b581

Please sign in to comment.