14 const auto hFile = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr);
15 if (hFile == INVALID_HANDLE_VALUE)
16 throw std::runtime_error{
"Failed to open \" + path.string() + \" for read-only"};
18 m_handle = CreateFileMappingW(hFile,
nullptr, PAGE_READONLY, 0, 0,
nullptr);
21 throw std::runtime_error{
"Failed to create file mapping"};
23 m_data =
static_cast<char*
>(MapViewOfFile(m_handle, FILE_MAP_READ, 0, 0, 0));
25 CloseHandle(m_handle);
27 m_fd = open(path.c_str(), O_RDONLY);
29 throw std::runtime_error{
"Failed to open \"" + path.string() +
"\" for read-only"};
31 m_bytes = (size_t)lseek(m_fd, 0, SEEK_END);
32 auto data = mmap(
nullptr, m_bytes, PROT_READ, MAP_PRIVATE, m_fd, 0);
33 if (
data != MAP_FAILED)
34 m_data =
static_cast<char*
>(
data);