memmappedfile-fix (#115)

Co-authored-by: Metehan Tuncbilek <mtuncbilek95@gmail.com>
Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
Co-authored-by: mtuncbilek <metehan.tuncbilek@madvoxel.com>
Co-committed-by: mtuncbilek <metehan.tuncbilek@madvoxel.com>
This commit is contained in:
mtuncbilek
2024-09-21 14:46:39 +02:00
committed by Georg Hagen
parent f6c48edac6
commit 95ddd4b23f
11 changed files with 801 additions and 114 deletions

View File

@@ -0,0 +1,50 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "MemMappedFile.hpp"
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
namespace OpenVulkano
{
class MemMappedFileInternal
{
friend class MemMappedFileWriteHelper;
friend class MemMappedFile;
public:
MemMappedFileInternal(const char* file, MemMappedFile::FileMode fileMode);
~MemMappedFileInternal();
private:
#if defined(_MSC_VER)
bool InvalidHandle() const { return fileHandle == INVALID_HANDLE_VALUE || fileHandle == NULL; }
#else
[[nodiscard]] bool InvalidHandle() const { return fileHandle == -1; }
#endif
private:
void* address = nullptr;
size_t size = 0;
#ifdef _MSC_VER
HANDLE fileHandle;
HANDLE fileMappingHandle;
#else
int fileHandle;
struct stat fileStat;
#endif
};
}