Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ if(CMAKE_SIZEOF_VOID_P LESS 8)
message(WARNING "Pointer size ${CMAKE_SIZEOF_VOID_P} is not supported. Please use a 64-bit compiler.")
endif()

# check CreateFile2 for mingw
INCLUDE(CheckCXXSourceCompiles)
if(MINGW)
check_cxx_source_compiles("#include <windows.h>
#include <fileapi.h>
int main() {
HANDLE h = CreateFile2(L\"nul\", GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL);
if (h != INVALID_HANDLE_VALUE) CloseHandle(h);
return 0;
}" HAVE_CREATEFILE2)

if(HAVE_CREATEFILE2)
add_compile_definitions(HAVE_CREATEFILE2)
endif()
endif()

# Set some variables that are used in-tree and while building based on our options
set(HTTPLIB_IS_COMPILED ${HTTPLIB_COMPILE})
set(HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN ${HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN})
Expand Down
5 changes: 5 additions & 0 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3078,8 +3078,13 @@ inline bool mmap::open(const char *path) {
auto wpath = u8string_to_wstring(path);
if (wpath.empty()) { return false; }

#if defined(HAVE_CREATEFILE2)
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; }

Expand Down