blob: bd0e4077d187a5845e6041ec1ecb74501b5ae1eb [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* vi: set sw=4 ts=4: */
2/*
3 * writev() for uClibc
4 *
5 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6 *
7 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 */
9
10#include <sys/syscall.h>
11#include <sys/uio.h>
12
13#ifdef __UCLIBC_HAS_THREADS_NATIVE__
14#include <errno.h>
15#include <sysdep-cancel.h>
16
17/* We should deal with kernel which have a smaller UIO_FASTIOV as well
18 as a very big count. */
19static ssize_t __writev (int fd, const struct iovec *vector, int count)
20{
21 ssize_t bytes_written;
22
23 bytes_written = INLINE_SYSCALL (writev, 3, fd, vector, count);
24
25 if (bytes_written >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
26 return bytes_written;
27
28 /* glibc tries again, but we do not. */
29 /* return __atomic_writev_replacement (fd, vector, count); */
30
31 return -1;
32}
33
34ssize_t writev (int fd, const struct iovec *vector, int count)
35{
36 if (SINGLE_THREAD_P)
37 return __writev (fd, vector, count);
38
39 int oldtype = LIBC_CANCEL_ASYNC ();
40
41 ssize_t result = __writev (fd, vector, count);
42
43 LIBC_CANCEL_RESET (oldtype);
44
45 return result;
46}
47#else
48_syscall3(ssize_t, writev, int, filedes, const struct iovec *, vector,
49 int, count)
50#endif