posix/fd: add pwrite wrapper

This commit is contained in:
Danny Robson 2018-12-17 12:44:09 +11:00
parent bb812ba81c
commit c34002ae07
2 changed files with 12 additions and 42 deletions

View File

@ -157,7 +157,7 @@ fd::read (void *buffer, std::size_t count)
}
///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
ssize_t
fd::write (const void *buffer, size_t count)
{
@ -167,6 +167,16 @@ fd::write (const void *buffer, size_t count)
}
//-----------------------------------------------------------------------------
ssize_t
fd::pwrite (const void *buf, size_t count, size_t offset)
{
return error::try_value (
::pwrite (native (), buf, count, offset)
);
}
///////////////////////////////////////////////////////////////////////////////
off_t
fd::lseek (off_t offset, int whence)

View File

@ -68,47 +68,7 @@ namespace cruft::posix {
//---------------------------------------------------------------------
[[nodiscard]] ssize_t read (void *buf, size_t count);
[[nodiscard]] ssize_t write (const void *buf, size_t count);
//---------------------------------------------------------------------
template <typename ValueT>
[[nodiscard]]
ValueT*
read (cruft::view<ValueT*> dst)
{
return dst.begin () + read (
&*std::data (dst), std::size (dst) * sizeof (ValueT)
);
}
//---------------------------------------------------------------------
template <typename ValueT>
[[nodiscard]]
auto
write (const cruft::view<ValueT*> &src)
{
return const_cast<ValueT*> (
write (
cruft::view<const ValueT*> (src)
)
);
}
//---------------------------------------------------------------------
template <typename ValueT>
[[nodiscard]]
const ValueT*
write (const cruft::view<const ValueT*> &src)
{
const auto written = write (
&*std::data (src), std::size (src) * sizeof (ValueT)
);
CHECK_MOD (written, sizeof (ValueT));
return src.begin () + written / sizeof (ValueT);
}
[[nodiscard]] ssize_t pwrite (const void *buf, size_t count, size_t offset);
//---------------------------------------------------------------------