From 7ffcbe9806206cbd5c86b825cefc94f1c39152ef Mon Sep 17 00:00:00 2001 From: Azim Afroozeh Date: Thu, 12 Sep 2024 00:33:18 +0200 Subject: [PATCH] try this --- include/fls/io/mmap.hpp | 3 --- src/io/mmap.cpp | 36 ------------------------------------ 2 files changed, 39 deletions(-) diff --git a/include/fls/io/mmap.hpp b/include/fls/io/mmap.hpp index 032aff9..9461037 100644 --- a/include/fls/io/mmap.hpp +++ b/include/fls/io/mmap.hpp @@ -7,9 +7,6 @@ namespace fastlanes { class Mmap { public: - static std::byte* Open(bsz_t bsz, int& fd, const std::filesystem::path& path); - template - static T* Open(bsz_t bsz, int& fd, const std::filesystem::path& path); static std::byte* Resize(bsz_t bsz, int& fd); template static T* Resize(bsz_t bsz, int& fd); diff --git a/src/io/mmap.cpp b/src/io/mmap.cpp index fb93a84..f2b8183 100644 --- a/src/io/mmap.cpp +++ b/src/io/mmap.cpp @@ -12,36 +12,6 @@ #include namespace fastlanes { -/* - * - * */ -std::byte* Mmap::Open(bsz_t init_bsz, int& fd, const std::filesystem::path& path) { - /**/ -#if defined(_WIN32) - // Use _open() on Windows - fd = open(path.c_str(), _O_RDWR | _O_CREAT, _S_IREAD | _S_IWRITE); -#else - // Use POSIX open() on Linux/macOS - fd = open(path.c_str(), O_RDWR | O_CREAT, 0777); -#endif - - if (fd == -1) { - /**/ - throw std::runtime_error(strerror(errno)); - } - - struct stat file_info {}; - if (stat(path.c_str(), &file_info) == -1) { throw std::runtime_error("stat"); } - - if (file_info.st_size == 0) { - if (ftruncate(fd, static_cast(init_bsz)) == -1) { throw std::runtime_error("Error resizing the file"); } - if (stat(path.c_str(), &file_info) == -1) { throw std::runtime_error("stat"); } - } - - auto* p = reinterpret_cast( - mmap(nullptr, static_cast(file_info.st_size), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); - return p; -} void Mmap::Close(void* p, bsz_t bsz, int& fd) { /**/ @@ -60,12 +30,6 @@ T* Mmap::Resize(bsz_t bsz, int& fd) { return reinterpret_cast(Resize(bsz, fd)); } -template -T* Mmap::Open(bsz_t bsz, int& fd, const std::filesystem::path& path) { - return reinterpret_cast(Open(bsz, fd, path)); -} - -template int64_t* Mmap::Open<>(bsz_t bsz, int& fd, const std::filesystem::path& path); template uint64_t* Mmap::Resize<>(bsz_t bsz, int& fd); } // namespace fastlanes \ No newline at end of file