posix/fd: add pwrite wrapper
This commit is contained in:
parent
bb812ba81c
commit
c34002ae07
12
posix/fd.cpp
12
posix/fd.cpp
@ -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)
|
||||
|
42
posix/fd.hpp
42
posix/fd.hpp
@ -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);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user