Back to index

glibc  2.9
readv.c
Go to the documentation of this file.
00001 /* readv supports all Linux kernels >= 2.0.
00002    Copyright (C) 1997,1998,2000,2002,2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <stddef.h>
00022 #include <sys/param.h>
00023 #include <sys/uio.h>
00024 
00025 #include <sysdep-cancel.h>
00026 #include <sys/syscall.h>
00027 #include <bp-checks.h>
00028 
00029 static ssize_t __atomic_readv_replacement (int, __const struct iovec *,
00030                                       int) internal_function;
00031 
00032 
00033 /* Not all versions of the kernel support the large number of records.  */
00034 #ifndef UIO_FASTIOV
00035 # define UIO_FASTIOV 8      /* 8 is a safe number.  */
00036 #endif
00037 
00038 
00039 /* We should deal with kernel which have a smaller UIO_FASTIOV as well
00040    as a very big count.  */
00041 static ssize_t
00042 do_readv (int fd, const struct iovec *vector, int count)
00043 {
00044   ssize_t bytes_read;
00045 
00046   bytes_read = INLINE_SYSCALL (readv, 3, fd, CHECK_N (vector, count), count);
00047 
00048   if (bytes_read >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
00049     return bytes_read;
00050 
00051   return __atomic_readv_replacement (fd, vector, count);
00052 }
00053 
00054 
00055 ssize_t
00056 __libc_readv (fd, vector, count)
00057      int fd;
00058      const struct iovec *vector;
00059      int count;
00060 {
00061   if (SINGLE_THREAD_P)
00062     return do_readv (fd, vector, count);
00063 
00064   int oldtype = LIBC_CANCEL_ASYNC ();
00065 
00066   int result = do_readv (fd, vector, count);
00067 
00068   LIBC_CANCEL_RESET (oldtype);
00069 
00070   return result;
00071 }
00072 strong_alias (__libc_readv, __readv)
00073 weak_alias (__libc_readv, readv)
00074 
00075 #define __libc_readv static internal_function __atomic_readv_replacement
00076 #include <sysdeps/posix/readv.c>