blob: 273221432b37b422b9fc4809ff3ae5b39f232c43 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 */
Elliott Hughesf4c948a2014-08-19 11:16:41 -070028
Elliott Hughes9c601772018-08-28 12:17:20 -070029#pragma once
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030
31#include <stddef.h>
32#include <sys/cdefs.h>
33#include <sys/types.h>
34#include <sys/select.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035
Josh Gaoee8d1692016-04-07 14:16:30 -070036#include <bits/fcntl.h>
David Benjamin71101572023-07-15 19:24:32 -040037#include <bits/getentropy.h>
Josh Gao7449e592016-04-07 16:37:49 -070038#include <bits/getopt.h>
Josh Gao98e574c2016-04-07 14:19:03 -070039#include <bits/ioctl.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080040#include <bits/lockf.h>
41#include <bits/posix_limits.h>
Elliott Hughesfd936ae2016-08-12 10:16:34 -070042#include <bits/seek_constants.h>
Josh Gao8c8ef592016-04-07 16:33:30 -070043#include <bits/sysconf.h>
Elliott Hughes1ed337d2015-02-02 14:02:09 -080044
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045__BEGIN_DECLS
46
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047#define STDIN_FILENO 0
48#define STDOUT_FILENO 1
49#define STDERR_FILENO 2
50
Elliott Hughes1ed337d2015-02-02 14:02:09 -080051#define F_OK 0
52#define X_OK 1
53#define W_OK 2
54#define R_OK 4
55
Elliott Hughesa186b2e2014-09-22 14:49:07 -070056#define _PC_FILESIZEBITS 0
57#define _PC_LINK_MAX 1
58#define _PC_MAX_CANON 2
59#define _PC_MAX_INPUT 3
60#define _PC_NAME_MAX 4
61#define _PC_PATH_MAX 5
62#define _PC_PIPE_BUF 6
63#define _PC_2_SYMLINKS 7
64#define _PC_ALLOC_SIZE_MIN 8
65#define _PC_REC_INCR_XFER_SIZE 9
66#define _PC_REC_MAX_XFER_SIZE 10
67#define _PC_REC_MIN_XFER_SIZE 11
68#define _PC_REC_XFER_ALIGN 12
69#define _PC_SYMLINK_MAX 13
70#define _PC_CHOWN_RESTRICTED 14
71#define _PC_NO_TRUNC 15
72#define _PC_VDISABLE 16
73#define _PC_ASYNC_IO 17
74#define _PC_PRIO_IO 18
75#define _PC_SYNC_IO 19
76
zijunzhao3d591102023-01-10 00:18:05 +000077extern char* _Nullable * _Nullable environ;
Elliott Hughes58d9e282014-04-22 17:41:00 -070078
Elliott Hughes3b2096a2016-07-22 18:57:12 -070079__noreturn void _exit(int __status);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080
Elliott Hughes2411fff2024-02-24 23:55:58 +000081/**
82 * [fork(2)](http://man7.org/linux/man-pages/man2/fork.2.html) creates a new
83 * process. fork() runs any handlers set by pthread_atfork().
84 *
85 * Returns 0 in the child, the pid of the child in the parent,
86 * and returns -1 and sets `errno` on failure.
87 */
88pid_t fork(void);
89
90/**
91 * _Fork() creates a new process. _Fork() differs from fork() in that it does
Elliott Hughes82572682024-03-04 22:24:01 +000092 * not run any handlers set by pthread_atfork(). In addition to any user-defined
93 * ones, bionic uses pthread_atfork() handlers to ensure consistency of its own
94 * state, so the child should only call
95 * [POSIX async-safe](https://man7.org/linux/man-pages/man7/signal-safety.7.html)
96 * functions.
Elliott Hughes2411fff2024-02-24 23:55:58 +000097 *
98 * Returns 0 in the child, the pid of the child in the parent,
99 * and returns -1 and sets `errno` on failure.
100 *
101 * Available since API level 35.
102 */
103pid_t _Fork(void) __INTRODUCED_IN(35);
104
105/**
106 * [vfork(2)](http://man7.org/linux/man-pages/man2/vfork.2.html) creates a new
107 * process. vfork() differs from fork() in that it does not run any handlers
108 * set by pthread_atfork(), and the parent is suspended until the child calls
109 * exec() or exits.
110 *
111 * Returns 0 in the child, the pid of the child in the parent,
112 * and returns -1 and sets `errno` on failure.
113 */
114pid_t vfork(void) __returns_twice;
115
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700116pid_t getpid(void);
Elliott Hughes95fa0612016-09-28 12:29:52 -0700117pid_t gettid(void) __attribute_const__;
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700118pid_t getpgid(pid_t __pid);
119int setpgid(pid_t __pid, pid_t __pgid);
120pid_t getppid(void);
121pid_t getpgrp(void);
122int setpgrp(void);
Elliott Hughes655e4302023-06-16 12:39:33 -0700123pid_t getsid(pid_t __pid);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700124pid_t setsid(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800125
zijunzhao3d591102023-01-10 00:18:05 +0000126int execv(const char* _Nonnull __path, char* _Nullable const* _Nullable __argv);
127int execvp(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv);
Elliott Hughes655e4302023-06-16 12:39:33 -0700128int execvpe(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp);
zijunzhao3d591102023-01-10 00:18:05 +0000129int execve(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp);
130int execl(const char* _Nonnull __path, const char* _Nullable __arg0, ...) __attribute__((__sentinel__));
131int execlp(const char* _Nonnull __file, const char* _Nullable __arg0, ...) __attribute__((__sentinel__));
132int execle(const char* _Nonnull __path, const char* _Nullable __arg0, ... /*, char* const* __envp */)
Josh Gaod80a52e2016-08-10 15:18:29 -0700133 __attribute__((__sentinel__(1)));
zijunzhao3d591102023-01-10 00:18:05 +0000134int fexecve(int __fd, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp) __INTRODUCED_IN(28);
David 'Digit' Turnerb083bb52011-05-26 02:46:41 +0200135
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700136int nice(int __incr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800137
Elliott Hughes9c601772018-08-28 12:17:20 -0700138/**
139 * [setegid(2)](http://man7.org/linux/man-pages/man2/setegid.2.html) sets
140 * the effective group ID.
141 *
142 * On Android, this function only affects the calling thread, not all threads
143 * in the process.
144 *
145 * Returns 0 on success, and returns -1 and sets `errno` on failure.
146 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700147int setegid(gid_t __gid);
Elliott Hughes9c601772018-08-28 12:17:20 -0700148
149/**
150 * [seteuid(2)](http://man7.org/linux/man-pages/man2/seteuid.2.html) sets
151 * the effective user ID.
152 *
153 * On Android, this function only affects the calling thread, not all threads
154 * in the process.
155 *
156 * Returns 0 on success, and returns -1 and sets `errno` on failure.
157 */
158int seteuid(uid_t __uid);
159
160/**
161 * [setgid(2)](http://man7.org/linux/man-pages/man2/setgid.2.html) sets
162 * the group ID.
163 *
164 * On Android, this function only affects the calling thread, not all threads
165 * in the process.
166 *
167 * Returns 0 on success, and returns -1 and sets `errno` on failure.
168 */
169int setgid(gid_t __gid);
170
171/**
172 * [setregid(2)](http://man7.org/linux/man-pages/man2/setregid.2.html) sets
173 * the real and effective group IDs (use -1 to leave an ID unchanged).
174 *
175 * On Android, this function only affects the calling thread, not all threads
176 * in the process.
177 *
178 * Returns 0 on success, and returns -1 and sets `errno` on failure.
179 */
180int setregid(gid_t __rgid, gid_t __egid);
181
182/**
183 * [setresgid(2)](http://man7.org/linux/man-pages/man2/setresgid.2.html) sets
184 * the real, effective, and saved group IDs (use -1 to leave an ID unchanged).
185 *
186 * On Android, this function only affects the calling thread, not all threads
187 * in the process.
188 *
189 * Returns 0 on success, and returns -1 and sets `errno` on failure.
190 */
191int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
192
193/**
194 * [setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html) sets
195 * the real, effective, and saved user IDs (use -1 to leave an ID unchanged).
196 *
197 * On Android, this function only affects the calling thread, not all threads
198 * in the process.
199 *
200 * Returns 0 on success, and returns -1 and sets `errno` on failure.
201 */
202int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
203
204/**
205 * [setreuid(2)](http://man7.org/linux/man-pages/man2/setreuid.2.html) sets
206 * the real and effective group IDs (use -1 to leave an ID unchanged).
207 *
208 * On Android, this function only affects the calling thread, not all threads
209 * in the process.
210 *
211 * Returns 0 on success, and returns -1 and sets `errno` on failure.
212 */
213int setreuid(uid_t __ruid, uid_t __euid);
214
215/**
216 * [setuid(2)](http://man7.org/linux/man-pages/man2/setuid.2.html) sets
217 * the user ID.
218 *
219 * On Android, this function only affects the calling thread, not all threads
220 * in the process.
221 *
222 * Returns 0 on success, and returns -1 and sets `errno` on failure.
223 */
224int setuid(uid_t __uid);
225
226uid_t getuid(void);
227uid_t geteuid(void);
228gid_t getgid(void);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700229gid_t getegid(void);
zijunzhao3d591102023-01-10 00:18:05 +0000230int getgroups(int __size, gid_t* _Nullable __list);
231int setgroups(size_t __size, const gid_t* _Nullable __list);
232int getresuid(uid_t* _Nonnull __ruid, uid_t* _Nonnull __euid, uid_t* _Nonnull __suid);
233int getresgid(gid_t* _Nonnull __rgid, gid_t* _Nonnull __egid, gid_t* _Nonnull __sgid);
234char* _Nullable getlogin(void);
235int getlogin_r(char* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800236
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700237long fpathconf(int __fd, int __name);
zijunzhao3d591102023-01-10 00:18:05 +0000238long pathconf(const char* _Nonnull __path, int __name);
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700239
zijunzhao3d591102023-01-10 00:18:05 +0000240int access(const char* _Nonnull __path, int __mode);
241int faccessat(int __dirfd, const char* _Nonnull __path, int __mode, int __flags);
242int link(const char* _Nonnull __old_path, const char* _Nonnull __new_path);
Elliott Hughes655e4302023-06-16 12:39:33 -0700243int linkat(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path, int __flags);
zijunzhao3d591102023-01-10 00:18:05 +0000244int unlink(const char* _Nonnull __path);
245int unlinkat(int __dirfd, const char* _Nonnull __path, int __flags);
246int chdir(const char* _Nonnull __path);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700247int fchdir(int __fd);
zijunzhao3d591102023-01-10 00:18:05 +0000248int rmdir(const char* _Nonnull __path);
249int pipe(int __fds[_Nonnull 2]);
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700250#if defined(__USE_GNU)
zijunzhao3d591102023-01-10 00:18:05 +0000251int pipe2(int __fds[_Nonnull 2], int __flags);
David 'Digit' Turner275cd482010-09-27 17:33:08 +0200252#endif
zijunzhao3d591102023-01-10 00:18:05 +0000253int chroot(const char* _Nonnull __path);
254int symlink(const char* _Nonnull __old_path, const char* _Nonnull __new_path);
Elliott Hughes655e4302023-06-16 12:39:33 -0700255int symlinkat(const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path);
zijunzhao3d591102023-01-10 00:18:05 +0000256ssize_t readlink(const char* _Nonnull __path, char* _Nonnull __buf, size_t __buf_size);
Elliott Hughes655e4302023-06-16 12:39:33 -0700257ssize_t readlinkat(int __dir_fd, const char* _Nonnull __path, char* _Nonnull __buf, size_t __buf_size);
zijunzhao3d591102023-01-10 00:18:05 +0000258int chown(const char* _Nonnull __path, uid_t __owner, gid_t __group);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700259int fchown(int __fd, uid_t __owner, gid_t __group);
zijunzhao3d591102023-01-10 00:18:05 +0000260int fchownat(int __dir_fd, const char* _Nonnull __path, uid_t __owner, gid_t __group, int __flags);
261int lchown(const char* _Nonnull __path, uid_t __owner, gid_t __group);
262char* _Nullable getcwd(char* _Nullable __buf, size_t __size);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800263
Elliott Hughes79a8f4b2016-11-29 15:16:08 -0800264void sync(void);
Elliott Hughes896362e2017-08-24 16:31:49 -0700265#if defined(__USE_GNU)
Elliott Hughescc0fe6e2018-01-30 08:54:12 -0800266int syncfs(int __fd) __INTRODUCED_IN(28);
Elliott Hughes896362e2017-08-24 16:31:49 -0700267#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800268
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700269int close(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800270
zijunzhao3d591102023-01-10 00:18:05 +0000271/**
272 * [read(2)](https://man7.org/linux/man-pages/man2/read.2.html) reads
273 * up to `__count` bytes from file descriptor `__fd` into `__buf`.
274 *
275 * Note: `__buf` is not normally nullable, but may be null in the
276 * special case of a zero-length read(), which while not generally
277 * useful may be meaningful to some device drivers.
278 *
279 * Returns the number of bytes read on success, and returns -1 and sets `errno` on failure.
280 */
281ssize_t read(int __fd, void* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __count);
282
283/**
284 * [write(2)](https://man7.org/linux/man-pages/man2/write.2.html) writes
285 * up to `__count` bytes to file descriptor `__fd` from `__buf`.
286 *
287 * Note: `__buf` is not normally nullable, but may be null in the
288 * special case of a zero-length write(), which while not generally
289 * useful may be meaningful to some device drivers.
290 *
291 * Returns the number of bytes written on success, and returns -1 and sets `errno` on failure.
292 */
293ssize_t write(int __fd, const void* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __count);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800294
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700295int dup(int __old_fd);
296int dup2(int __old_fd, int __new_fd);
Elliott Hughes655e4302023-06-16 12:39:33 -0700297int dup3(int __old_fd, int __new_fd, int __flags);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700298int fsync(int __fd);
Elliott Hughesf106a392019-10-03 16:09:04 -0700299int fdatasync(int __fd);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800300
Elliott Hughes9c06d162023-10-04 23:36:14 +0000301/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
Elliott Hughes00fedf52017-07-05 15:23:50 -0700302#if defined(__USE_FILE_OFFSET64)
Elliott Hughes655e4302023-06-16 12:39:33 -0700303int truncate(const char* _Nonnull __path, off_t __length) __RENAME(truncate64);
Elliott Hughesa3481742017-11-28 14:47:17 -0800304off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
zijunzhao3d591102023-01-10 00:18:05 +0000305ssize_t pread(int __fd, void* _Nonnull __buf, size_t __count, off_t __offset) __RENAME(pread64);
306ssize_t pwrite(int __fd, const void* _Nonnull __buf, size_t __count, off_t __offset) __RENAME(pwrite64);
Elliott Hughes0e14c5a2019-10-03 20:35:38 -0700307int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64);
Dan Albertaf4713e2015-09-04 12:59:53 -0700308#else
zijunzhao3d591102023-01-10 00:18:05 +0000309int truncate(const char* _Nonnull __path, off_t __length);
Elliott Hughesa3481742017-11-28 14:47:17 -0800310off_t lseek(int __fd, off_t __offset, int __whence);
zijunzhao3d591102023-01-10 00:18:05 +0000311ssize_t pread(int __fd, void* _Nonnull __buf, size_t __count, off_t __offset);
312ssize_t pwrite(int __fd, const void* _Nonnull __buf, size_t __count, off_t __offset);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700313int ftruncate(int __fd, off_t __length);
Dan Albertaf4713e2015-09-04 12:59:53 -0700314#endif
315
Elliott Hughes655e4302023-06-16 12:39:33 -0700316int truncate64(const char* _Nonnull __path, off64_t __length);
Elliott Hughesa3481742017-11-28 14:47:17 -0800317off64_t lseek64(int __fd, off64_t __offset, int __whence);
zijunzhao3d591102023-01-10 00:18:05 +0000318ssize_t pread64(int __fd, void* _Nonnull __buf, size_t __count, off64_t __offset);
319ssize_t pwrite64(int __fd, const void* _Nonnull __buf, size_t __count, off64_t __offset);
Elliott Hughes0e14c5a2019-10-03 20:35:38 -0700320int ftruncate64(int __fd, off64_t __length);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800321
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700322int pause(void);
323unsigned int alarm(unsigned int __seconds);
324unsigned int sleep(unsigned int __seconds);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700325int usleep(useconds_t __microseconds);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800326
zijunzhao3d591102023-01-10 00:18:05 +0000327int gethostname(char* _Nonnull _buf, size_t __buf_size);
328int sethostname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800329
zijunzhao3d591102023-01-10 00:18:05 +0000330int brk(void* _Nonnull __addr);
331void* _Nullable sbrk(ptrdiff_t __increment);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800332
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700333int isatty(int __fd);
zijunzhao3d591102023-01-10 00:18:05 +0000334char* _Nullable ttyname(int __fd);
335int ttyname_r(int __fd, char* _Nonnull __buf, size_t __buf_size);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800336
zijunzhao3d591102023-01-10 00:18:05 +0000337int acct(const char* _Nullable __path);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800338
Elliott Hughes3bfb6ee2024-03-27 21:23:42 +0000339/**
340 * [getpagesize(2)](https://man7.org/linux/man-pages/man2/getpagesize.2.html)
341 * returns the system's page size. This is slightly faster than going via
342 * sysconf().
343 *
344 * Returns the system's page size in bytes.
345 */
Elliott Hughesc77993e2023-06-23 18:29:51 +0000346int getpagesize(void) __attribute_const__;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800347
Dan Albertaf4713e2015-09-04 12:59:53 -0700348long syscall(long __number, ...);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800349
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700350int daemon(int __no_chdir, int __no_close);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800351
Elliott Hughes5ac438e2020-02-13 15:56:31 -0800352#if defined(__arm__)
Elliott Hughes9b9371b2024-04-22 20:17:22 +0000353/**
354 * New code should use __builtin___clear_cache() instead, which works on
355 * all architectures.
356 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700357int cacheflush(long __addr, long __nbytes, long __cache);
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800358#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800359
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700360pid_t tcgetpgrp(int __fd);
361int tcsetpgrp(int __fd, pid_t __pid);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800362
Elliott Hughescf399f72009-10-05 13:19:05 -0700363/* Used to retry syscalls that can return EINTR. */
364#define TEMP_FAILURE_RETRY(exp) ({ \
Dan Alberta7821b72014-05-21 20:33:28 -0700365 __typeof__(exp) _rc; \
Elliott Hughescf399f72009-10-05 13:19:05 -0700366 do { \
367 _rc = (exp); \
368 } while (_rc == -1 && errno == EINTR); \
369 _rc; })
370
zijunzhao3d591102023-01-10 00:18:05 +0000371int getdomainname(char* _Nonnull __buf, size_t __buf_size) __INTRODUCED_IN(26);
372int setdomainname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(26);
Greg Hackmanne2faf072016-03-03 08:37:53 -0800373
zijunzhaoc2e412e2022-04-22 18:08:09 +0000374/**
375 * [copy_file_range(2)](https://man7.org/linux/man-pages/man2/copy_file_range.2.html) copies
376 * a range of data from one file descriptor to another.
377 *
zijunzhaoc2e412e2022-04-22 18:08:09 +0000378 * Available since API level 34.
Elliott Hughesd4fd67c2022-11-30 19:53:33 +0000379 *
380 * Returns the number of bytes copied on success, and returns -1 and sets
381 * `errno` on failure.
zijunzhaoc2e412e2022-04-22 18:08:09 +0000382 */
zijunzhao3d591102023-01-10 00:18:05 +0000383ssize_t copy_file_range(int __fd_in, off64_t* _Nullable __off_in, int __fd_out, off64_t* _Nullable __off_out, size_t __length, unsigned int __flags) __INTRODUCED_IN(34);
zijunzhaoc2e412e2022-04-22 18:08:09 +0000384
Dan Albert2dbea432019-06-14 14:19:22 -0700385#if __ANDROID_API__ >= 28
zijunzhao3d591102023-01-10 00:18:05 +0000386void swab(const void* _Nonnull __src, void* _Nonnull __dst, ssize_t __byte_count) __INTRODUCED_IN(28);
Dan Albert2dbea432019-06-14 14:19:22 -0700387#endif
Elliott Hughesfa386e02017-10-18 13:34:32 -0700388
Maciej Żenczykowskib65e1052022-01-21 11:19:55 -0800389/**
390 * [close_range(2)](https://man7.org/linux/man-pages/man2/close_range.2.html)
391 * performs an action (which depends on value of flags) on an inclusive range
392 * of file descriptors.
393 *
394 * Available since API level 34.
395 *
396 * Note: there is no emulation on too old kernels, hence this will fail with
397 * -1/ENOSYS on pre-5.9 kernels, -1/EINVAL for unsupported flags. In particular
398 * CLOSE_RANGE_CLOEXEC requires 5.11, though support was backported to Android
399 * Common Kernel 5.10-T.
400 *
401 * Returns 0 on success, and returns -1 and sets `errno` on failure.
402 */
403int close_range(unsigned int __min_fd, unsigned int __max_fd, int __flags) __INTRODUCED_IN(34);
404
George Burgess IVb97049c2017-07-24 15:05:05 -0700405#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
Elliott Hughes9c601772018-08-28 12:17:20 -0700406#define _UNISTD_H_
George Burgess IVb97049c2017-07-24 15:05:05 -0700407#include <bits/fortify/unistd.h>
Elliott Hughes9c601772018-08-28 12:17:20 -0700408#undef _UNISTD_H_
George Burgess IV7cc779f2017-02-09 00:00:31 -0800409#endif
Daniel Micay9101b002015-05-20 15:31:26 -0400410
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800411__END_DECLS
Dan Albert2dbea432019-06-14 14:19:22 -0700412
413#include <android/legacy_unistd_inlines.h>