From b7838fb9fe18dce682cd7101004a73e4bbfdbf52 Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Fri, 13 Jan 2023 23:16:30 +0100 Subject: [PATCH 1/2] add cmake and apple compability --- CMakeLists.txt | 8 ++++++++ MemoryMapped.cpp | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4780ad4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(portable-memory-mapping + MemoryMapped.cpp + MemoryMapped.h +) + +target_include_directories(portable-memory-mapping INTERFACE ./) + +target_link_libraries(portable-memory-mapping) diff --git a/MemoryMapped.cpp b/MemoryMapped.cpp index eac4fd3..486d935 100644 --- a/MemoryMapped.cpp +++ b/MemoryMapped.cpp @@ -30,7 +30,10 @@ #include #include #endif - +#if __APPLE__ +#define stat64 stat +#define fstat64 fstat +#endif /// do nothing, must use open() MemoryMapped::MemoryMapped() @@ -118,7 +121,11 @@ bool MemoryMapped::open(const std::string& filename, size_t mappedBytes, CacheHi // Linux // open file +#ifdef __APPLE__ + _file = ::open(filename.c_str(), O_RDONLY); +#else _file = ::open(filename.c_str(), O_RDONLY | O_LARGEFILE); +#endif if (_file == -1) { _file = 0; @@ -276,9 +283,13 @@ bool MemoryMapped::remap(uint64_t offset, size_t mappedBytes) #else +#ifdef __APPLE__ + _mappedView = ::mmap(NULL, mappedBytes, PROT_READ, MAP_SHARED, _file, offset); +#else // Linux // new mapping _mappedView = ::mmap64(NULL, mappedBytes, PROT_READ, MAP_SHARED, _file, offset); +#endif if (_mappedView == MAP_FAILED) { _mappedBytes = 0; From 80bacea4be25f443d0e0820840b1042c4807f321 Mon Sep 17 00:00:00 2001 From: Fred <27208977+FreddyFunk@users.noreply.github.com> Date: Fri, 13 Jan 2023 23:34:48 +0100 Subject: [PATCH 2/2] default to static lib --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4780ad4..2a25d4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(portable-memory-mapping +add_library(portable-memory-mapping STATIC MemoryMapped.cpp MemoryMapped.h )