You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/09/22 02:31:17 UTC

[incubator-nuttx] branch master updated: libc/uio: enable writev() for sockets

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new a1c047f  libc/uio: enable writev() for sockets
a1c047f is described below

commit a1c047fe53ca29b7af87c3289ebf25f685443075
Author: spiriou <si...@korys.io>
AuthorDate: Mon Sep 21 11:37:48 2020 +0200

    libc/uio: enable writev() for sockets
---
 libs/libc/uio/lib_writev.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libs/libc/uio/lib_writev.c b/libs/libc/uio/lib_writev.c
index 00da0a8..7f92a70 100644
--- a/libs/libc/uio/lib_writev.c
+++ b/libs/libc/uio/lib_writev.c
@@ -52,9 +52,10 @@
  * Description:
  *   The writev() function is equivalent to write(), except as described
  *   below. The writev() function will gather output data from the 'iovcnt'
- *   buffers specified by the members of the 'iov' array: iov[0], iov[1], ...,
- *   iov[iovcnt-1]. The 'iovcnt' argument is valid if greater than 0 and less
- *   than or equal to IOV_MAX, as defined in limits.h.
+ *   buffers specified by the members of the 'iov' array:
+ *   iov[0], iov[1], ..., iov[iovcnt-1].
+ *   The 'iovcnt' argument is valid if greater than 0 and less than or equal
+ *   to IOV_MAX, as defined in limits.h.
  *
  *   Each iovec entry specifies the base address and length of an area in
  *   memory from which data should be written. The writev() function always
@@ -98,10 +99,6 @@ ssize_t writev(int fildes, FAR const struct iovec *iov, int iovcnt)
   /* Get the current file position in case we have to reset it */
 
   pos = lseek(fildes, 0, SEEK_CUR);
-  if (pos == (off_t)-1)
-    {
-      return ERROR;
-    }
 
   /* Process each entry in the struct iovec array */
 
@@ -126,17 +123,21 @@ ssize_t writev(int fildes, FAR const struct iovec *iov, int iovcnt)
 
               if (nwritten < 0)
                 {
-                  /* Save the errno value */
+                  if (pos != (off_t)-1)
+                    {
+                      /* Save the errno value */
+
+                      int save = get_errno();
 
-                  int save = get_errno();
+                      /* Restore the file position */
 
-                  /* Restore the file position */
+                      lseek(fildes, pos, SEEK_SET);
 
-                  lseek(fildes, pos, SEEK_SET);
+                      /* Restore the errno value */
 
-                  /* Restore the errno value */
+                      set_errno(save);
+                    }
 
-                  set_errno(save);
                   return ERROR;
                 }