diff --git a/include/dwarfs/mmap.h b/include/dwarfs/mmap.h
index e4ed52b4..3ec9c207 100644
--- a/include/dwarfs/mmap.h
+++ b/include/dwarfs/mmap.h
@@ -32,10 +32,7 @@ namespace dwarfs {
class mmap : public mmif {
public:
explicit mmap(std::filesystem::path const& path);
- explicit mmap(std::string const& path);
- explicit mmap(char const* path);
mmap(std::filesystem::path const& path, size_t size);
- mmap(std::string const& path, size_t size);
void const* addr() const override;
size_t size() const override;
diff --git a/src/mmap.cpp b/src/mmap.cpp
index e204430e..51a0000d 100644
--- a/src/mmap.cpp
+++ b/src/mmap.cpp
@@ -19,18 +19,16 @@
* along with dwarfs. If not, see .
*/
-#include
#include
#ifdef _WIN32
+#include
#include
#else
#include
#include
#endif
-#include
-
#include
#include
@@ -63,17 +61,17 @@ int posix_advice(advice adv) {
return MADV_DONTNEED;
}
- assert(false);
+ DWARFS_PANIC("invalid advice");
return MADV_NORMAL;
}
#endif
-boost::filesystem::path boost_from_std_path(std::filesystem::path const& p) {
+decltype(auto) get_file_path(std::filesystem::path const& path) {
#ifdef _WIN32
- return {p.wstring()};
+ return boost::filesystem::path{path.native()};
#else
- return {p.string()};
+ return path.native();
#endif
}
@@ -144,28 +142,18 @@ size_t mmap::size() const { return mf_.size(); }
std::filesystem::path const& mmap::path() const { return path_; }
-mmap::mmap(char const* path)
- : mmap(std::filesystem::path(path)) {}
-
-mmap::mmap(std::string const& path)
- : mmap(std::filesystem::path(path)) {}
-
mmap::mmap(std::filesystem::path const& path)
- : mf_(boost_from_std_path(path), boost::iostreams::mapped_file::readonly)
- , page_size_(get_page_size())
+ : mf_{get_file_path(path), boost::iostreams::mapped_file::readonly}
+ , page_size_{get_page_size()}
, path_{path} {
- assert(mf_.is_open());
+ DWARFS_CHECK(mf_.is_open(), "failed to map file");
}
-mmap::mmap(std::string const& path, size_t size)
- : mmap(std::filesystem::path(path), size) {}
-
mmap::mmap(std::filesystem::path const& path, size_t size)
- : mf_(boost_from_std_path(path), boost::iostreams::mapped_file::readonly,
- size)
- , page_size_(get_page_size())
+ : mf_{get_file_path(path), boost::iostreams::mapped_file::readonly, size}
+ , page_size_{get_page_size()}
, path_{path} {
- assert(mf_.is_open());
+ DWARFS_CHECK(mf_.is_open(), "failed to map file");
}
} // namespace dwarfs