io: use size_t result for mapped_file::size

This commit is contained in:
Danny Robson 2016-10-25 19:57:13 +11:00
parent c04b153242
commit 1662856e82
2 changed files with 12 additions and 4 deletions

View File

@ -19,6 +19,7 @@
#include "debug.hpp" #include "debug.hpp"
#include "except.hpp" #include "except.hpp"
#include "posix/fd.hpp" #include "posix/fd.hpp"
#include "./cast.hpp"
#include <sys/stat.h> #include <sys/stat.h>
@ -38,7 +39,7 @@ mapped_file::mapped_file (const ::util::posix::fd &src, int mflags)
if (fstat (src, &meta) < 0) if (fstat (src, &meta) < 0)
throw errno_error (); throw errno_error ();
m_size = meta.st_size; m_size = sign_cast<size_t> (meta.st_size);
m_data = (uint8_t *)mmap (NULL, m_size, mflags, MAP_SHARED, src, 0); m_data = (uint8_t *)mmap (NULL, m_size, mflags, MAP_SHARED, src, 0);
if (m_data == MAP_FAILED) if (m_data == MAP_FAILED)
throw errno_error (); throw errno_error ();
@ -54,7 +55,7 @@ mapped_file::~mapped_file ()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
intmax_t size_t
mapped_file::size (void) const mapped_file::size (void) const
{ {
return m_size; return m_size;

View File

@ -40,7 +40,14 @@ namespace util {
~mapped_file (); ~mapped_file ();
bool empty (void) const; 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 &; const uint8_t* data (void) const &;
uint8_t* data (void) &; uint8_t* data (void) &;
@ -64,7 +71,7 @@ namespace util {
private: private:
uint8_t *m_data; uint8_t *m_data;
intmax_t m_size; size_t m_size;
}; };
} } } }