Skip to content

Commit

Permalink
Implement file mapping for UWP apps (yhirose#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-nsk authored Feb 9, 2024
1 parent 5c00bbf commit ad40bd6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2686,21 +2686,29 @@ inline bool mmap::open(const char *path) {
close();

#if defined(_WIN32)
hFile_ = ::CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
std::wstring wpath;
for (size_t i = 0; i < strlen(path); i++) {
wpath += path[i];
}

hFile_ = ::CreateFile2(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ,
OPEN_EXISTING, NULL);

if (hFile_ == INVALID_HANDLE_VALUE) { return false; }

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

hMapping_ = ::CreateFileMapping(hFile_, NULL, PAGE_READONLY, 0, 0, NULL);
hMapping_ = ::CreateFileMappingFromApp(hFile_, NULL, PAGE_READONLY, size_,
NULL);

if (hMapping_ == NULL) {
close();
return false;
}

addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0);
addr_ = ::MapViewOfFileFromApp(hMapping_, FILE_MAP_READ, 0, 0);
#else
fd_ = ::open(path, O_RDONLY);
if (fd_ == -1) { return false; }
Expand Down

0 comments on commit ad40bd6

Please sign in to comment.