about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-03-21 20:32:12 +0000
committerUlrich Drepper <drepper@redhat.com>1997-03-21 20:32:12 +0000
commita16d0942d7d51559e3740e239c3401a352356e7c (patch)
treeaed19c31c818cf9fce935b1dee15302c6002b677
parentfea444e4d2274833b218a1abdd2111da7577df52 (diff)
downloadglibc-a16d0942d7d51559e3740e239c3401a352356e7c.tar.gz
glibc-a16d0942d7d51559e3740e239c3401a352356e7c.tar.xz
glibc-a16d0942d7d51559e3740e239c3401a352356e7c.zip
Don't emulate readv with small UIO_FASTIOV value by multiple readv
calls since we need atomicity.
-rw-r--r--sysdeps/unix/sysv/linux/readv.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/sysdeps/unix/sysv/linux/readv.c b/sysdeps/unix/sysv/linux/readv.c
index c8ff55ab45..2c215ce920 100644
--- a/sysdeps/unix/sysv/linux/readv.c
+++ b/sysdeps/unix/sysv/linux/readv.c
@@ -23,6 +23,8 @@
 #include <sys/uio.h>
 
 extern ssize_t __syscall_readv __P ((int, __const struct iovec *, int));
+static ssize_t __atomic_readv_replacement __P ((int, __const struct iovec *,
+						int));
 
 
 /* Not all versions of the kernel support the large number of records.  */
@@ -34,7 +36,7 @@ extern ssize_t __syscall_readv __P ((int, __const struct iovec *, int));
 /* We should deal with kernel which have a smaller UIO_FASTIOV as well
    as a very big count.  */
 ssize_t
-readv (fd, vector, count)
+__readv (fd, vector, count)
      int fd;
      const struct iovec *vector;
      int count;
@@ -44,25 +46,15 @@ readv (fd, vector, count)
 
   bytes_read = __syscall_readv (fd, vector, count);
 
-  if (bytes_read < 0 && errno == EINVAL && count > UIO_FASTIOV)
-    {
-      int i;
+  if (bytes_read >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
+    return bytes_read;
 
-      /* Restore the old error value as if nothing happened.  */
-      __set_errno (errno_saved);
+  /* Restore the old error value as if nothing happened.  */
+  __set_errno (errno_saved);
 
-      bytes_read = 0;
-      for (i = 0; i < count; i += UIO_FASTIOV)
-	{
-	  ssize_t bytes = __syscall_readv (fd, vector + i,
-					   MIN (count - i, UIO_FASTIOV));
-
-	  if (bytes < 0)
-	    return bytes;
-
-	  bytes_read += bytes;
-	}
-    }
-
-  return bytes_read;
+  return __atomic_readv_replacement (fd, vector, count);
 }
+weak_alias (__readv, readv)
+
+#define __readv static __atomic_readv_replacement
+#include <sysdeps/posix/readv.c>