io: use size_t result for mapped_file::size
This commit is contained in:
parent
c04b153242
commit
1662856e82
@ -19,6 +19,7 @@
|
||||
#include "debug.hpp"
|
||||
#include "except.hpp"
|
||||
#include "posix/fd.hpp"
|
||||
#include "./cast.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
@ -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<size_t> (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;
|
||||
|
11
io_posix.hpp
11
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;
|
||||
};
|
||||
} }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user