posix/fd: prefer error::try_value over explicit checks
This commit is contained in:
parent
77c88438d4
commit
c22a5a2a07
39
posix/fd.cpp
39
posix/fd.cpp
@ -33,11 +33,8 @@ fd::fd (const std::experimental::filesystem::path &path, int flags):
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
fd::fd (const std::experimental::filesystem::path &path, int flags, mode_t mode):
|
fd::fd (const std::experimental::filesystem::path &path, int flags, mode_t mode):
|
||||||
m_fd (::open (path.c_str (), flags, mode))
|
m_fd (error::try_value (::open (path.c_str (), flags, mode)))
|
||||||
{
|
{ ; }
|
||||||
if (m_fd < 0)
|
|
||||||
error::throw_code ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -66,11 +63,9 @@ fd::dup (void) const
|
|||||||
fd
|
fd
|
||||||
fd::dup (int _fd)
|
fd::dup (int _fd)
|
||||||
{
|
{
|
||||||
auto res = ::dup (_fd);
|
return fd {
|
||||||
if (res < 0)
|
error::try_value (::dup (_fd))
|
||||||
error::throw_code ();
|
};
|
||||||
|
|
||||||
return fd (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,8 +75,7 @@ fd::~fd ()
|
|||||||
if (m_fd < 0)
|
if (m_fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (close (m_fd))
|
error::try_code (close (m_fd));
|
||||||
error::throw_code ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -100,20 +94,18 @@ fd::stat (void) const
|
|||||||
ssize_t
|
ssize_t
|
||||||
fd::read (void *buffer, size_t count)
|
fd::read (void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
auto res = ::read (m_fd, buffer, count);
|
return error::try_value (
|
||||||
if (res == -1)
|
::read (m_fd, buffer, count)
|
||||||
error::throw_code ();
|
);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
ssize_t
|
ssize_t
|
||||||
fd::write (const void *buffer, size_t count)
|
fd::write (const void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
auto res = ::write (m_fd, buffer, count);
|
return error::try_value (
|
||||||
if (res == -1)
|
::write (m_fd, buffer, count)
|
||||||
error::throw_code ();
|
);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -121,10 +113,9 @@ fd::write (const void *buffer, size_t count)
|
|||||||
off_t
|
off_t
|
||||||
fd::lseek (off_t offset, int whence)
|
fd::lseek (off_t offset, int whence)
|
||||||
{
|
{
|
||||||
auto res = ::lseek (m_fd, offset, whence);
|
return error::try_value (
|
||||||
if (res == -1)
|
::lseek (m_fd, offset, whence)
|
||||||
error::throw_code ();
|
);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user