diff --git a/io_posix.cpp b/io_posix.cpp index 0d3056a9..f4b612d0 100644 --- a/io_posix.cpp +++ b/io_posix.cpp @@ -19,6 +19,7 @@ #include "debug.hpp" #include "except.hpp" #include "posix/fd.hpp" +#include "./cast.hpp" #include @@ -38,7 +39,7 @@ mapped_file::mapped_file (const ::util::posix::fd &src, int mflags) if (fstat (src, &meta) < 0) throw errno_error (); - m_size = meta.st_size; + m_size = sign_cast (meta.st_size); m_data = (uint8_t *)mmap (NULL, m_size, mflags, MAP_SHARED, src, 0); if (m_data == MAP_FAILED) throw errno_error (); @@ -54,7 +55,7 @@ mapped_file::~mapped_file () //---------------------------------------------------------------------------- -intmax_t +size_t mapped_file::size (void) const { return m_size; diff --git a/io_posix.hpp b/io_posix.hpp index e924c6d6..2d00b4f1 100644 --- a/io_posix.hpp +++ b/io_posix.hpp @@ -40,7 +40,14 @@ namespace util { ~mapped_file (); bool empty (void) const; - intmax_t size (void) const; + + /// returns the total allocated mapped region in bytes. + /// + /// result is typed size_t (rather than a signed type) because we + /// often use this in conjunction with sizeof and packed structure. + /// it is greatly simpler to cast to signed where it's actually + /// required rather than the other way around. + size_t size (void) const; const uint8_t* data (void) const &; uint8_t* data (void) &; @@ -64,7 +71,7 @@ namespace util { private: uint8_t *m_data; - intmax_t m_size; + size_t m_size; }; } }