posix/fd: add read and write member functions

This commit is contained in:
Danny Robson 2016-10-11 20:58:19 +11:00
parent cf7fda382a
commit 4196702b38
2 changed files with 25 additions and 0 deletions

View File

@ -96,6 +96,27 @@ fd::stat (void) const
}
///////////////////////////////////////////////////////////////////////////////
ssize_t
fd::read (void *buffer, size_t count)
{
auto res = ::read (m_fd, buffer, count);
if (res == -1)
errno_error::throw_code ();
return res;
}
//-----------------------------------------------------------------------------
ssize_t
fd::write (const void *buffer, size_t count)
{
auto res = ::write (m_fd, buffer, count);
if (res == -1)
errno_error::throw_code ();
return res;
}
///////////////////////////////////////////////////////////////////////////////
fd::operator int (void) const
{

View File

@ -53,6 +53,10 @@ namespace util::posix {
///////////////////////////////////////////////////////////////////////
struct ::stat stat (void) const;
//---------------------------------------------------------------------
ssize_t read ( void *buf, size_t count);
ssize_t write (const void *buf, size_t count);
///////////////////////////////////////////////////////////////////////
operator int (void) const;