From bfcd63ec654e8705ac968befe53ca3a348a09c5b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 19 Dec 2017 18:12:01 +1100 Subject: [PATCH] posix/fd: add read overloads that take char/byte views --- posix/fd.cpp | 9 +++++++++ posix/fd.hpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/posix/fd.cpp b/posix/fd.cpp index c322b77a..8044c8f2 100644 --- a/posix/fd.cpp +++ b/posix/fd.cpp @@ -99,8 +99,17 @@ fd::read (void *buffer, size_t count) ); } + //----------------------------------------------------------------------------- ssize_t +fd::read (util::view dst) +{ + return read (std::data (dst), std::size (dst)); +} + + +/////////////////////////////////////////////////////////////////////////////// +ssize_t fd::write (const void *buffer, size_t count) { return error::try_value ( diff --git a/posix/fd.hpp b/posix/fd.hpp index 05e00cf2..3c1192c2 100644 --- a/posix/fd.hpp +++ b/posix/fd.hpp @@ -11,12 +11,14 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2016 Danny Robson + * Copyright 2017 Danny Robson */ #ifndef __CRUFT_UTIL_POSIX_FD_HPP #define __CRUFT_UTIL_POSIX_FD_HPP +#include "../view.hpp" + #include #include @@ -52,8 +54,13 @@ namespace util::posix { struct ::stat stat (void) const; //--------------------------------------------------------------------- - [[gnu::warn_unused_result]] ssize_t read ( void *buf, size_t count); + [[gnu::warn_unused_result]] ssize_t read (void *buf, size_t count); + [[gnu::warn_unused_result]] ssize_t read (util::view); + [[gnu::warn_unused_result]] ssize_t read (util::view); + [[gnu::warn_unused_result]] ssize_t write (const void *buf, size_t count); + [[gnu::warn_unused_result]] ssize_t write (util::view); + [[gnu::warn_unused_result]] ssize_t write (util::view); //--------------------------------------------------------------------- [[gnu::warn_unused_result]] off_t lseek (off_t offset, int whence);