Back to index

glibc  2.9
writev.c
Go to the documentation of this file.
00001 /* writev 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_writev_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_writev (int fd, const struct iovec *vector, int count)
00043 {
00044   ssize_t bytes_written;
00045 
00046   bytes_written = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
00047 
00048   if (bytes_written >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
00049     return bytes_written;
00050 
00051   return __atomic_writev_replacement (fd, vector, count);
00052 }
00053 
00054 ssize_t
00055 __libc_writev (fd, vector, count)
00056      int fd;
00057      const struct iovec *vector;
00058      int count;
00059 {
00060   if (SINGLE_THREAD_P)
00061     return do_writev (fd, vector, count);
00062 
00063   int oldtype = LIBC_CANCEL_ASYNC ();
00064 
00065   ssize_t result = do_writev (fd, vector, count);
00066 
00067   LIBC_CANCEL_RESET (oldtype);
00068 
00069   return result;
00070 }
00071 strong_alias (__libc_writev, __writev)
00072 weak_alias (__libc_writev, writev)
00073 
00074 #define __libc_writev static internal_function __atomic_writev_replacement
00075 #include <sysdeps/posix/writev.c>