1997-03-19 05:47:56 +00:00
|
|
|
/* writev supports all Linux kernels >= 2.0.
|
2003-09-03 03:22:23 +00:00
|
|
|
Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
|
1997-03-19 05:47:56 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-03-19 05:47:56 +00:00
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-03-19 05:47:56 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with the GNU C Library; if not, write to the Free
|
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
|
02111-1307 USA. */
|
1997-03-19 05:47:56 +00:00
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
2002-12-15 10:26:23 +00:00
|
|
|
#include <sysdep-cancel.h>
|
1998-10-21 15:29:52 +00:00
|
|
|
#include <sys/syscall.h>
|
2000-07-07 02:19:06 +00:00
|
|
|
#include <bp-checks.h>
|
1998-10-21 15:29:52 +00:00
|
|
|
|
2000-05-23 08:43:26 +00:00
|
|
|
static ssize_t __atomic_writev_replacement (int, const struct iovec *,
|
|
|
|
|
int) internal_function;
|
1997-03-21 20:00:48 +00:00
|
|
|
|
1997-03-19 05:47:56 +00:00
|
|
|
|
|
|
|
|
/* Not all versions of the kernel support the large number of records. */
|
1997-03-20 02:20:57 +00:00
|
|
|
#ifndef UIO_FASTIOV
|
|
|
|
|
# define UIO_FASTIOV 8 /* 8 is a safe number. */
|
1997-03-19 05:47:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
1997-03-20 02:20:57 +00:00
|
|
|
/* We should deal with kernel which have a smaller UIO_FASTIOV as well
|
1997-03-19 05:47:56 +00:00
|
|
|
as a very big count. */
|
2002-12-15 10:26:23 +00:00
|
|
|
static ssize_t
|
|
|
|
|
do_writev (int fd, const struct iovec *vector, int count)
|
1997-03-19 05:47:56 +00:00
|
|
|
{
|
|
|
|
|
ssize_t bytes_written;
|
|
|
|
|
|
2000-07-07 02:19:06 +00:00
|
|
|
bytes_written = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
|
1997-03-19 05:47:56 +00:00
|
|
|
|
1997-03-21 20:00:48 +00:00
|
|
|
if (bytes_written >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
|
|
|
|
|
return bytes_written;
|
1997-03-19 05:47:56 +00:00
|
|
|
|
1997-03-21 20:00:48 +00:00
|
|
|
return __atomic_writev_replacement (fd, vector, count);
|
1997-03-19 05:47:56 +00:00
|
|
|
}
|
2002-12-15 10:26:23 +00:00
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
|
__libc_writev (fd, vector, count)
|
|
|
|
|
int fd;
|
|
|
|
|
const struct iovec *vector;
|
|
|
|
|
int count;
|
|
|
|
|
{
|
|
|
|
|
if (SINGLE_THREAD_P)
|
|
|
|
|
return do_writev (fd, vector, count);
|
|
|
|
|
|
|
|
|
|
int oldtype = LIBC_CANCEL_ASYNC ();
|
|
|
|
|
|
|
|
|
|
ssize_t result = do_writev (fd, vector, count);
|
|
|
|
|
|
|
|
|
|
LIBC_CANCEL_RESET (oldtype);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2002-10-09 09:42:48 +00:00
|
|
|
strong_alias (__libc_writev, __writev)
|
|
|
|
|
weak_alias (__libc_writev, writev)
|
1997-03-21 20:00:48 +00:00
|
|
|
|
2002-10-09 09:42:48 +00:00
|
|
|
#define __libc_writev static internal_function __atomic_writev_replacement
|
1997-03-21 20:00:48 +00:00
|
|
|
#include <sysdeps/posix/writev.c>
|