[rtems commit] libio: Unify readv() and writev()

Sebastian Huber sebh at rtems.org
Fri Sep 15 09:01:13 UTC 2017


Module:    rtems
Branch:    master
Commit:    98041b685e9cbe4916d8684372389e899698da16
Changeset: http://git.rtems.org/rtems/commit/?id=98041b685e9cbe4916d8684372389e899698da16

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Sep 13 15:19:14 2017 +0200

libio: Unify readv() and writev()

Update #3132.

---

 cpukit/libcsupport/include/rtems/libio_.h | 22 ++++++++++++++++------
 cpukit/libcsupport/src/readv.c            | 27 +++++++++++++++++----------
 cpukit/libcsupport/src/writev.c           | 27 +++++++++++++++++----------
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index 9bf8320..adf137d 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -921,12 +921,19 @@ static inline bool rtems_filesystem_is_parent_directory(
   return tokenlen == 2 && token [0] == '.' && token [1] == '.';
 }
 
-static inline ssize_t rtems_libio_iovec_eval(
-  int fd,
+typedef ssize_t ( *rtems_libio_iovec_adapter )(
+  rtems_libio_t      *iop,
   const struct iovec *iov,
-  int iovcnt,
-  uint32_t flags,
-  rtems_libio_t **iopp
+  int                 iovcnt,
+  ssize_t             total
+);
+
+static inline ssize_t rtems_libio_iovec_eval(
+  int                        fd,
+  const struct iovec        *iov,
+  int                        iovcnt,
+  uint32_t                   flags,
+  rtems_libio_iovec_adapter  adapter
 )
 {
   ssize_t        total;
@@ -966,7 +973,10 @@ static inline ssize_t rtems_libio_iovec_eval(
   }
 
   LIBIO_GET_IOP_WITH_ACCESS( fd, iop, flags, EBADF );
-  *iopp = iop;
+
+  if ( total > 0 ) {
+    total = ( *adapter )( iop, iov, iovcnt, total );
+  }
 
   return total;
 }
diff --git a/cpukit/libcsupport/src/readv.c b/cpukit/libcsupport/src/readv.c
index 8c901ca..6d4f1b3 100644
--- a/cpukit/libcsupport/src/readv.c
+++ b/cpukit/libcsupport/src/readv.c
@@ -22,6 +22,16 @@
 
 #include <rtems/libio_.h>
 
+static ssize_t readv_adapter(
+  rtems_libio_t      *iop,
+  const struct iovec *iov,
+  int                 iovcnt,
+  ssize_t             total
+)
+{
+  return ( *iop->pathinfo.handlers->readv_h )( iop, iov, iovcnt, total );
+}
+
 /**
  *  readv() - POSIX 1003.1 - Read a Vector
  *
@@ -35,14 +45,11 @@ ssize_t readv(
   int                 iovcnt
 )
 {
-  ssize_t        total;
-  rtems_libio_t *iop;
-
-  total = rtems_libio_iovec_eval( fd, iov, iovcnt, LIBIO_FLAGS_READ, &iop );
-
-  if ( total > 0 ) {
-    total = ( *iop->pathinfo.handlers->readv_h )( iop, iov, iovcnt, total );
-  }
-
-  return total;
+  return rtems_libio_iovec_eval(
+    fd,
+    iov,
+    iovcnt,
+    LIBIO_FLAGS_READ,
+    readv_adapter
+  );
 }
diff --git a/cpukit/libcsupport/src/writev.c b/cpukit/libcsupport/src/writev.c
index c566329..ad3d8dc 100644
--- a/cpukit/libcsupport/src/writev.c
+++ b/cpukit/libcsupport/src/writev.c
@@ -21,20 +21,27 @@
 
 #include <rtems/libio_.h>
 
+static ssize_t writev_adapter(
+  rtems_libio_t      *iop,
+  const struct iovec *iov,
+  int                 iovcnt,
+  ssize_t             total
+)
+{
+  return ( *iop->pathinfo.handlers->writev_h )( iop, iov, iovcnt, total );
+}
+
 ssize_t writev(
   int                 fd,
   const struct iovec *iov,
   int                 iovcnt
 )
 {
-  ssize_t        total;
-  rtems_libio_t *iop;
-
-  total = rtems_libio_iovec_eval( fd, iov, iovcnt, LIBIO_FLAGS_WRITE, &iop );
-
-  if ( total > 0 ) {
-    total = ( *iop->pathinfo.handlers->writev_h )( iop, iov, iovcnt, total );
-  }
-
-  return total;
+  return rtems_libio_iovec_eval(
+    fd,
+    iov,
+    iovcnt,
+    LIBIO_FLAGS_WRITE,
+    writev_adapter
+  );
 }




More information about the vc mailing list