1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 /**
32  * @file sys/uio.h
33  * @brief Multi-buffer ("vector") I/O operations using `struct iovec`.
34  */
35 
36 #include <sys/cdefs.h>
37 #include <sys/types.h>
38 #include <linux/uio.h>
39 
40 __BEGIN_DECLS
41 
42 /**
43  * [readv(2)](https://man7.org/linux/man-pages/man2/readv.2.html) reads
44  * from an fd into the `__count` buffers described by `__iov`.
45  *
46  * Returns the number of bytes read on success,
47  * and returns -1 and sets `errno` on failure.
48  */
49 ssize_t readv(int __fd, const struct iovec* _Nonnull __iov, int __count);
50 
51 /**
52  * [writev(2)](https://man7.org/linux/man-pages/man2/writev.2.html) writes
53  * to an fd from the `__count` buffers described by `__iov`.
54  *
55  * Returns the number of bytes written on success,
56  * and returns -1 and sets `errno` on failure.
57  */
58 ssize_t writev(int __fd, const struct iovec* _Nonnull __iov, int __count);
59 
60 #if defined(__USE_GNU)
61 
62 /**
63  * [preadv(2)](https://man7.org/linux/man-pages/man2/preadv.2.html) reads
64  * from an fd into the `__count` buffers described by `__iov`, starting at
65  * offset `__offset` into the file.
66  *
67  * Returns the number of bytes read on success,
68  * and returns -1 and sets `errno` on failure.
69  *
70  * Available since API level 24.
71  */
72 
73 #if __BIONIC_AVAILABILITY_GUARD(24)
74 ssize_t preadv(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset) __RENAME_IF_FILE_OFFSET64(preadv64) __INTRODUCED_IN(24);
75 
76 /**
77  * [pwritev(2)](https://man7.org/linux/man-pages/man2/pwritev.2.html) writes
78  * to an fd from the `__count` buffers described by `__iov`, starting at offset
79  * `__offset` into the file.
80  *
81  * Returns the number of bytes written on success,
82  * and returns -1 and sets `errno` on failure.
83  *
84  * Available since API level 24.
85  */
86 ssize_t pwritev(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset) __RENAME_IF_FILE_OFFSET64(pwritev64) __INTRODUCED_IN(24);
87 
88 /**
89  * Like preadv() but with a 64-bit offset even in a 32-bit process.
90  *
91  * Available since API level 24.
92  */
93 ssize_t preadv64(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset) __INTRODUCED_IN(24);
94 
95 /**
96  * Like pwritev() but with a 64-bit offset even in a 32-bit process.
97  *
98  * Available since API level 24.
99  */
100 ssize_t pwritev64(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset) __INTRODUCED_IN(24);
101 #endif /* __BIONIC_AVAILABILITY_GUARD(24) */
102 
103 
104 /**
105  * [preadv2(2)](https://man7.org/linux/man-pages/man2/preadv2.2.html) reads
106  * from an fd into the `__count` buffers described by `__iov`, starting at
107  * offset `__offset` into the file, with the given flags.
108  *
109  * Returns the number of bytes read on success,
110  * and returns -1 and sets `errno` on failure.
111  *
112  * Available since API level 33.
113  */
114 
115 #if __BIONIC_AVAILABILITY_GUARD(33)
116 ssize_t preadv2(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset, int __flags) __RENAME_IF_FILE_OFFSET64(preadv64v2) __INTRODUCED_IN(33);
117 
118 /**
119  * [pwritev2(2)](https://man7.org/linux/man-pages/man2/pwritev2.2.html) writes
120  * to an fd from the `__count` buffers described by `__iov`, starting at offset
121  * `__offset` into the file, with the given flags.
122  *
123  * Returns the number of bytes written on success,
124  * and returns -1 and sets `errno` on failure.
125  *
126  * Available since API level 33.
127  */
128 ssize_t pwritev2(int __fd, const struct iovec* _Nonnull __iov, int __count, off_t __offset, int __flags) __RENAME_IF_FILE_OFFSET64(pwritev64v2) __INTRODUCED_IN(33);
129 
130 /**
131  * Like preadv2() but with a 64-bit offset even in a 32-bit process.
132  *
133  * Available since API level 33.
134  */
135 ssize_t preadv64v2(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset, int __flags) __INTRODUCED_IN(33);
136 
137 /**
138  * Like pwritev2() but with a 64-bit offset even in a 32-bit process.
139  *
140  * Available since API level 33.
141  */
142 ssize_t pwritev64v2(int __fd, const struct iovec* _Nonnull __iov, int __count, off64_t __offset, int __flags) __INTRODUCED_IN(33);
143 #endif /* __BIONIC_AVAILABILITY_GUARD(33) */
144 
145 
146 /**
147  * [process_vm_readv(2)](https://man7.org/linux/man-pages/man2/process_vm_readv.2.html)
148  * reads from the address space of another process.
149  *
150  * Returns the number of bytes read on success,
151  * and returns -1 and sets `errno` on failure.
152  *
153  * Available since API level 23.
154  */
155 
156 #if __BIONIC_AVAILABILITY_GUARD(23)
157 ssize_t process_vm_readv(pid_t __pid, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __local_iov, unsigned long __local_iov_count, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23);
158 
159 /**
160  * [process_vm_writev(2)](https://man7.org/linux/man-pages/man2/process_vm_writev.2.html)
161  * writes to the address space of another process.
162  *
163  * Returns the number of bytes read on success,
164  * and returns -1 and sets `errno` on failure.
165  *
166  * Available since API level 23.
167  */
168 ssize_t process_vm_writev(pid_t __pid, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __local_iov, unsigned long __local_iov_count, const struct iovec* __BIONIC_COMPLICATED_NULLNESS __remote_iov, unsigned long __remote_iov_count, unsigned long __flags) __INTRODUCED_IN(23);
169 #endif /* __BIONIC_AVAILABILITY_GUARD(23) */
170 
171 
172 #endif
173 
174 __END_DECLS
175