The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | */ |
Elliott Hughes | f4c948a | 2014-08-19 11:16:41 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 29 | #pragma once |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 31 | #include <sys/cdefs.h> |
Elliott Hughes | 414dd2d | 2024-10-16 14:48:30 +0000 | [diff] [blame^] | 32 | |
| 33 | #include <stddef.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | #include <sys/types.h> |
| 35 | #include <sys/select.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | |
Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 37 | #include <bits/fcntl.h> |
David Benjamin | 7110157 | 2023-07-15 19:24:32 -0400 | [diff] [blame] | 38 | #include <bits/getentropy.h> |
Josh Gao | 7449e59 | 2016-04-07 16:37:49 -0700 | [diff] [blame] | 39 | #include <bits/getopt.h> |
Josh Gao | 98e574c | 2016-04-07 14:19:03 -0700 | [diff] [blame] | 40 | #include <bits/ioctl.h> |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 41 | #include <bits/lockf.h> |
| 42 | #include <bits/posix_limits.h> |
Elliott Hughes | fd936ae | 2016-08-12 10:16:34 -0700 | [diff] [blame] | 43 | #include <bits/seek_constants.h> |
Josh Gao | 8c8ef59 | 2016-04-07 16:33:30 -0700 | [diff] [blame] | 44 | #include <bits/sysconf.h> |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 45 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 46 | __BEGIN_DECLS |
| 47 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 48 | #define STDIN_FILENO 0 |
| 49 | #define STDOUT_FILENO 1 |
| 50 | #define STDERR_FILENO 2 |
| 51 | |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 52 | #define F_OK 0 |
| 53 | #define X_OK 1 |
| 54 | #define W_OK 2 |
| 55 | #define R_OK 4 |
| 56 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 57 | #define _PC_FILESIZEBITS 0 |
| 58 | #define _PC_LINK_MAX 1 |
| 59 | #define _PC_MAX_CANON 2 |
| 60 | #define _PC_MAX_INPUT 3 |
| 61 | #define _PC_NAME_MAX 4 |
| 62 | #define _PC_PATH_MAX 5 |
| 63 | #define _PC_PIPE_BUF 6 |
| 64 | #define _PC_2_SYMLINKS 7 |
| 65 | #define _PC_ALLOC_SIZE_MIN 8 |
| 66 | #define _PC_REC_INCR_XFER_SIZE 9 |
| 67 | #define _PC_REC_MAX_XFER_SIZE 10 |
| 68 | #define _PC_REC_MIN_XFER_SIZE 11 |
| 69 | #define _PC_REC_XFER_ALIGN 12 |
| 70 | #define _PC_SYMLINK_MAX 13 |
| 71 | #define _PC_CHOWN_RESTRICTED 14 |
| 72 | #define _PC_NO_TRUNC 15 |
| 73 | #define _PC_VDISABLE 16 |
| 74 | #define _PC_ASYNC_IO 17 |
| 75 | #define _PC_PRIO_IO 18 |
| 76 | #define _PC_SYNC_IO 19 |
| 77 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 78 | extern char* _Nullable * _Nullable environ; |
Elliott Hughes | 58d9e28 | 2014-04-22 17:41:00 -0700 | [diff] [blame] | 79 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 80 | __noreturn void _exit(int __status); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | |
Elliott Hughes | 2411fff | 2024-02-24 23:55:58 +0000 | [diff] [blame] | 82 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 83 | * [fork(2)](https://man7.org/linux/man-pages/man2/fork.2.html) creates a new |
Elliott Hughes | 2411fff | 2024-02-24 23:55:58 +0000 | [diff] [blame] | 84 | * process. fork() runs any handlers set by pthread_atfork(). |
| 85 | * |
| 86 | * Returns 0 in the child, the pid of the child in the parent, |
| 87 | * and returns -1 and sets `errno` on failure. |
| 88 | */ |
| 89 | pid_t fork(void); |
| 90 | |
| 91 | /** |
| 92 | * _Fork() creates a new process. _Fork() differs from fork() in that it does |
Elliott Hughes | 8257268 | 2024-03-04 22:24:01 +0000 | [diff] [blame] | 93 | * not run any handlers set by pthread_atfork(). In addition to any user-defined |
| 94 | * ones, bionic uses pthread_atfork() handlers to ensure consistency of its own |
| 95 | * state, so the child should only call |
| 96 | * [POSIX async-safe](https://man7.org/linux/man-pages/man7/signal-safety.7.html) |
| 97 | * functions. |
Elliott Hughes | 2411fff | 2024-02-24 23:55:58 +0000 | [diff] [blame] | 98 | * |
| 99 | * Returns 0 in the child, the pid of the child in the parent, |
| 100 | * and returns -1 and sets `errno` on failure. |
| 101 | * |
| 102 | * Available since API level 35. |
| 103 | */ |
| 104 | pid_t _Fork(void) __INTRODUCED_IN(35); |
| 105 | |
| 106 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 107 | * [vfork(2)](https://man7.org/linux/man-pages/man2/vfork.2.html) creates a new |
Elliott Hughes | 2411fff | 2024-02-24 23:55:58 +0000 | [diff] [blame] | 108 | * process. vfork() differs from fork() in that it does not run any handlers |
| 109 | * set by pthread_atfork(), and the parent is suspended until the child calls |
| 110 | * exec() or exits. |
| 111 | * |
| 112 | * Returns 0 in the child, the pid of the child in the parent, |
| 113 | * and returns -1 and sets `errno` on failure. |
| 114 | */ |
| 115 | pid_t vfork(void) __returns_twice; |
| 116 | |
Elliott Hughes | c8ea872 | 2024-05-28 15:23:52 +0000 | [diff] [blame] | 117 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 118 | * [getpid(2)](https://man7.org/linux/man-pages/man2/getpid.2.html) returns |
Elliott Hughes | c8ea872 | 2024-05-28 15:23:52 +0000 | [diff] [blame] | 119 | * the caller's process ID. |
| 120 | * |
| 121 | * Returns the caller's process ID. |
| 122 | */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 123 | pid_t getpid(void); |
Elliott Hughes | c8ea872 | 2024-05-28 15:23:52 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 126 | * [gettid(2)](https://man7.org/linux/man-pages/man2/gettid.2.html) returns |
Elliott Hughes | c8ea872 | 2024-05-28 15:23:52 +0000 | [diff] [blame] | 127 | * the caller's thread ID. |
| 128 | * |
| 129 | * Returns the caller's thread ID. |
| 130 | */ |
| 131 | pid_t gettid(void); |
| 132 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 133 | pid_t getpgid(pid_t __pid); |
| 134 | int setpgid(pid_t __pid, pid_t __pgid); |
| 135 | pid_t getppid(void); |
| 136 | pid_t getpgrp(void); |
| 137 | int setpgrp(void); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 138 | pid_t getsid(pid_t __pid); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 139 | pid_t setsid(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 140 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 141 | int execv(const char* _Nonnull __path, char* _Nullable const* _Nullable __argv); |
| 142 | int execvp(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 143 | int execvpe(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 144 | int execve(const char* _Nonnull __file, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp); |
| 145 | int execl(const char* _Nonnull __path, const char* _Nullable __arg0, ...) __attribute__((__sentinel__)); |
| 146 | int execlp(const char* _Nonnull __file, const char* _Nullable __arg0, ...) __attribute__((__sentinel__)); |
| 147 | int execle(const char* _Nonnull __path, const char* _Nullable __arg0, ... /*, char* const* __envp */) |
Josh Gao | d80a52e | 2016-08-10 15:18:29 -0700 | [diff] [blame] | 148 | __attribute__((__sentinel__(1))); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 149 | int fexecve(int __fd, char* _Nullable const* _Nullable __argv, char* _Nullable const* _Nullable __envp) __INTRODUCED_IN(28); |
David 'Digit' Turner | b083bb5 | 2011-05-26 02:46:41 +0200 | [diff] [blame] | 150 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 151 | int nice(int __incr); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 152 | |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 153 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 154 | * [setegid(2)](https://man7.org/linux/man-pages/man2/setegid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 155 | * the effective group ID. |
| 156 | * |
| 157 | * On Android, this function only affects the calling thread, not all threads |
| 158 | * in the process. |
| 159 | * |
| 160 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 161 | */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 162 | int setegid(gid_t __gid); |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 165 | * [seteuid(2)](https://man7.org/linux/man-pages/man2/seteuid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 166 | * the effective user ID. |
| 167 | * |
| 168 | * On Android, this function only affects the calling thread, not all threads |
| 169 | * in the process. |
| 170 | * |
| 171 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 172 | */ |
| 173 | int seteuid(uid_t __uid); |
| 174 | |
| 175 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 176 | * [setgid(2)](https://man7.org/linux/man-pages/man2/setgid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 177 | * the group ID. |
| 178 | * |
| 179 | * On Android, this function only affects the calling thread, not all threads |
| 180 | * in the process. |
| 181 | * |
| 182 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 183 | */ |
| 184 | int setgid(gid_t __gid); |
| 185 | |
| 186 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 187 | * [setregid(2)](https://man7.org/linux/man-pages/man2/setregid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 188 | * the real and effective group IDs (use -1 to leave an ID unchanged). |
| 189 | * |
| 190 | * On Android, this function only affects the calling thread, not all threads |
| 191 | * in the process. |
| 192 | * |
| 193 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 194 | */ |
| 195 | int setregid(gid_t __rgid, gid_t __egid); |
| 196 | |
| 197 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 198 | * [setresgid(2)](https://man7.org/linux/man-pages/man2/setresgid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 199 | * the real, effective, and saved group IDs (use -1 to leave an ID unchanged). |
| 200 | * |
| 201 | * On Android, this function only affects the calling thread, not all threads |
| 202 | * in the process. |
| 203 | * |
| 204 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 205 | */ |
| 206 | int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid); |
| 207 | |
| 208 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 209 | * [setresuid(2)](https://man7.org/linux/man-pages/man2/setresuid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 210 | * the real, effective, and saved user IDs (use -1 to leave an ID unchanged). |
| 211 | * |
| 212 | * On Android, this function only affects the calling thread, not all threads |
| 213 | * in the process. |
| 214 | * |
| 215 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 216 | */ |
| 217 | int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid); |
| 218 | |
| 219 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 220 | * [setreuid(2)](https://man7.org/linux/man-pages/man2/setreuid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 221 | * the real and effective group IDs (use -1 to leave an ID unchanged). |
| 222 | * |
| 223 | * On Android, this function only affects the calling thread, not all threads |
| 224 | * in the process. |
| 225 | * |
| 226 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 227 | */ |
| 228 | int setreuid(uid_t __ruid, uid_t __euid); |
| 229 | |
| 230 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 231 | * [setuid(2)](https://man7.org/linux/man-pages/man2/setuid.2.html) sets |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 232 | * the user ID. |
| 233 | * |
| 234 | * On Android, this function only affects the calling thread, not all threads |
| 235 | * in the process. |
| 236 | * |
| 237 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 238 | */ |
| 239 | int setuid(uid_t __uid); |
| 240 | |
| 241 | uid_t getuid(void); |
| 242 | uid_t geteuid(void); |
| 243 | gid_t getgid(void); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 244 | gid_t getegid(void); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 245 | int getgroups(int __size, gid_t* _Nullable __list); |
| 246 | int setgroups(size_t __size, const gid_t* _Nullable __list); |
| 247 | int getresuid(uid_t* _Nonnull __ruid, uid_t* _Nonnull __euid, uid_t* _Nonnull __suid); |
| 248 | int getresgid(gid_t* _Nonnull __rgid, gid_t* _Nonnull __egid, gid_t* _Nonnull __sgid); |
| 249 | char* _Nullable getlogin(void); |
| 250 | int getlogin_r(char* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 251 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 252 | long fpathconf(int __fd, int __name); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 253 | long pathconf(const char* _Nonnull __path, int __name); |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 254 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 255 | int access(const char* _Nonnull __path, int __mode); |
| 256 | int faccessat(int __dirfd, const char* _Nonnull __path, int __mode, int __flags); |
| 257 | int link(const char* _Nonnull __old_path, const char* _Nonnull __new_path); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 258 | int linkat(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path, int __flags); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 259 | int unlink(const char* _Nonnull __path); |
| 260 | int unlinkat(int __dirfd, const char* _Nonnull __path, int __flags); |
Elliott Hughes | fb9df25 | 2024-09-24 15:38:22 +0000 | [diff] [blame] | 261 | |
| 262 | /** |
| 263 | * [chdir(2)](https://man7.org/linux/man-pages/man2/chdir.2.html) changes |
| 264 | * the current working directory to the given path. |
| 265 | * |
| 266 | * This function affects all threads in the process, so is generally a bad idea |
| 267 | * on Android where most code will be running in a multi-threaded context. |
| 268 | * |
| 269 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 270 | */ |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 271 | int chdir(const char* _Nonnull __path); |
Elliott Hughes | fb9df25 | 2024-09-24 15:38:22 +0000 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * [fchdir(2)](https://man7.org/linux/man-pages/man2/chdir.2.html) changes |
| 275 | * the current working directory to the given fd. |
| 276 | * |
| 277 | * This function affects all threads in the process, so is generally a bad idea |
| 278 | * on Android where most code will be running in a multi-threaded context. |
| 279 | * |
| 280 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 281 | */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 282 | int fchdir(int __fd); |
Elliott Hughes | fb9df25 | 2024-09-24 15:38:22 +0000 | [diff] [blame] | 283 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 284 | int rmdir(const char* _Nonnull __path); |
| 285 | int pipe(int __fds[_Nonnull 2]); |
Elliott Hughes | 5f5cc45 | 2014-08-18 16:04:03 -0700 | [diff] [blame] | 286 | #if defined(__USE_GNU) |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 287 | int pipe2(int __fds[_Nonnull 2], int __flags); |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 288 | #endif |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 289 | int chroot(const char* _Nonnull __path); |
| 290 | int symlink(const char* _Nonnull __old_path, const char* _Nonnull __new_path); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 291 | int symlinkat(const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 292 | ssize_t readlink(const char* _Nonnull __path, char* _Nonnull __buf, size_t __buf_size); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 293 | ssize_t readlinkat(int __dir_fd, const char* _Nonnull __path, char* _Nonnull __buf, size_t __buf_size); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 294 | int chown(const char* _Nonnull __path, uid_t __owner, gid_t __group); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 295 | int fchown(int __fd, uid_t __owner, gid_t __group); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 296 | int fchownat(int __dir_fd, const char* _Nonnull __path, uid_t __owner, gid_t __group, int __flags); |
| 297 | int lchown(const char* _Nonnull __path, uid_t __owner, gid_t __group); |
| 298 | char* _Nullable getcwd(char* _Nullable __buf, size_t __size); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 299 | |
Elliott Hughes | 79a8f4b | 2016-11-29 15:16:08 -0800 | [diff] [blame] | 300 | void sync(void); |
Elliott Hughes | 896362e | 2017-08-24 16:31:49 -0700 | [diff] [blame] | 301 | #if defined(__USE_GNU) |
Elliott Hughes | cc0fe6e | 2018-01-30 08:54:12 -0800 | [diff] [blame] | 302 | int syncfs(int __fd) __INTRODUCED_IN(28); |
Elliott Hughes | 896362e | 2017-08-24 16:31:49 -0700 | [diff] [blame] | 303 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 304 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 305 | int close(int __fd); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 306 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 307 | /** |
| 308 | * [read(2)](https://man7.org/linux/man-pages/man2/read.2.html) reads |
| 309 | * up to `__count` bytes from file descriptor `__fd` into `__buf`. |
| 310 | * |
| 311 | * Note: `__buf` is not normally nullable, but may be null in the |
| 312 | * special case of a zero-length read(), which while not generally |
| 313 | * useful may be meaningful to some device drivers. |
| 314 | * |
| 315 | * Returns the number of bytes read on success, and returns -1 and sets `errno` on failure. |
| 316 | */ |
| 317 | ssize_t read(int __fd, void* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __count); |
| 318 | |
| 319 | /** |
| 320 | * [write(2)](https://man7.org/linux/man-pages/man2/write.2.html) writes |
| 321 | * up to `__count` bytes to file descriptor `__fd` from `__buf`. |
| 322 | * |
| 323 | * Note: `__buf` is not normally nullable, but may be null in the |
| 324 | * special case of a zero-length write(), which while not generally |
| 325 | * useful may be meaningful to some device drivers. |
| 326 | * |
| 327 | * Returns the number of bytes written on success, and returns -1 and sets `errno` on failure. |
| 328 | */ |
| 329 | ssize_t write(int __fd, const void* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __count); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 330 | |
Elliott Hughes | bda6f3b | 2017-08-25 15:07:05 -0700 | [diff] [blame] | 331 | int dup(int __old_fd); |
| 332 | int dup2(int __old_fd, int __new_fd); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 333 | int dup3(int __old_fd, int __new_fd, int __flags); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 334 | int fsync(int __fd); |
Elliott Hughes | f106a39 | 2019-10-03 16:09:04 -0700 | [diff] [blame] | 335 | int fdatasync(int __fd); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 336 | |
Elliott Hughes | 9c06d16 | 2023-10-04 23:36:14 +0000 | [diff] [blame] | 337 | /* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */ |
Elliott Hughes | 00fedf5 | 2017-07-05 15:23:50 -0700 | [diff] [blame] | 338 | #if defined(__USE_FILE_OFFSET64) |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 339 | int truncate(const char* _Nonnull __path, off_t __length) __RENAME(truncate64); |
Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame] | 340 | off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 341 | ssize_t pread(int __fd, void* _Nonnull __buf, size_t __count, off_t __offset) __RENAME(pread64); |
| 342 | ssize_t pwrite(int __fd, const void* _Nonnull __buf, size_t __count, off_t __offset) __RENAME(pwrite64); |
Elliott Hughes | 0e14c5a | 2019-10-03 20:35:38 -0700 | [diff] [blame] | 343 | int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 344 | #else |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 345 | int truncate(const char* _Nonnull __path, off_t __length); |
Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame] | 346 | off_t lseek(int __fd, off_t __offset, int __whence); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 347 | ssize_t pread(int __fd, void* _Nonnull __buf, size_t __count, off_t __offset); |
| 348 | ssize_t pwrite(int __fd, const void* _Nonnull __buf, size_t __count, off_t __offset); |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 349 | int ftruncate(int __fd, off_t __length); |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 350 | #endif |
| 351 | |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 352 | int truncate64(const char* _Nonnull __path, off64_t __length); |
Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame] | 353 | off64_t lseek64(int __fd, off64_t __offset, int __whence); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 354 | ssize_t pread64(int __fd, void* _Nonnull __buf, size_t __count, off64_t __offset); |
| 355 | ssize_t pwrite64(int __fd, const void* _Nonnull __buf, size_t __count, off64_t __offset); |
Elliott Hughes | 0e14c5a | 2019-10-03 20:35:38 -0700 | [diff] [blame] | 356 | int ftruncate64(int __fd, off64_t __length); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 357 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 358 | int pause(void); |
| 359 | unsigned int alarm(unsigned int __seconds); |
| 360 | unsigned int sleep(unsigned int __seconds); |
Elliott Hughes | bda6f3b | 2017-08-25 15:07:05 -0700 | [diff] [blame] | 361 | int usleep(useconds_t __microseconds); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 362 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 363 | int gethostname(char* _Nonnull _buf, size_t __buf_size); |
| 364 | int sethostname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(23); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 365 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 366 | int brk(void* _Nonnull __addr); |
| 367 | void* _Nullable sbrk(ptrdiff_t __increment); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 368 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 369 | int isatty(int __fd); |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 370 | char* _Nullable ttyname(int __fd); |
| 371 | int ttyname_r(int __fd, char* _Nonnull __buf, size_t __buf_size); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 372 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 373 | int acct(const char* _Nullable __path); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 374 | |
Elliott Hughes | 3bfb6ee | 2024-03-27 21:23:42 +0000 | [diff] [blame] | 375 | /** |
| 376 | * [getpagesize(2)](https://man7.org/linux/man-pages/man2/getpagesize.2.html) |
| 377 | * returns the system's page size. This is slightly faster than going via |
Elliott Hughes | b631ec7 | 2024-06-03 19:19:22 +0000 | [diff] [blame] | 378 | * sysconf(), and avoids the linear search in getauxval(). |
Elliott Hughes | 3bfb6ee | 2024-03-27 21:23:42 +0000 | [diff] [blame] | 379 | * |
| 380 | * Returns the system's page size in bytes. |
| 381 | */ |
Elliott Hughes | c77993e | 2023-06-23 18:29:51 +0000 | [diff] [blame] | 382 | int getpagesize(void) __attribute_const__; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 383 | |
Dan Albert | af4713e | 2015-09-04 12:59:53 -0700 | [diff] [blame] | 384 | long syscall(long __number, ...); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 385 | |
Elliott Hughes | bda6f3b | 2017-08-25 15:07:05 -0700 | [diff] [blame] | 386 | int daemon(int __no_chdir, int __no_close); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 387 | |
Elliott Hughes | 5ac438e | 2020-02-13 15:56:31 -0800 | [diff] [blame] | 388 | #if defined(__arm__) |
Elliott Hughes | 9b9371b | 2024-04-22 20:17:22 +0000 | [diff] [blame] | 389 | /** |
| 390 | * New code should use __builtin___clear_cache() instead, which works on |
| 391 | * all architectures. |
| 392 | */ |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 393 | int cacheflush(long __addr, long __nbytes, long __cache); |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 394 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 395 | |
Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 396 | pid_t tcgetpgrp(int __fd); |
| 397 | int tcsetpgrp(int __fd, pid_t __pid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 398 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 399 | /* Used to retry syscalls that can return EINTR. */ |
| 400 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
Dan Albert | a7821b7 | 2014-05-21 20:33:28 -0700 | [diff] [blame] | 401 | __typeof__(exp) _rc; \ |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 402 | do { \ |
| 403 | _rc = (exp); \ |
| 404 | } while (_rc == -1 && errno == EINTR); \ |
| 405 | _rc; }) |
| 406 | |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 407 | int getdomainname(char* _Nonnull __buf, size_t __buf_size) __INTRODUCED_IN(26); |
| 408 | int setdomainname(const char* _Nonnull __name, size_t __n) __INTRODUCED_IN(26); |
Greg Hackmann | e2faf07 | 2016-03-03 08:37:53 -0800 | [diff] [blame] | 409 | |
zijunzhao | c2e412e | 2022-04-22 18:08:09 +0000 | [diff] [blame] | 410 | /** |
| 411 | * [copy_file_range(2)](https://man7.org/linux/man-pages/man2/copy_file_range.2.html) copies |
| 412 | * a range of data from one file descriptor to another. |
| 413 | * |
zijunzhao | c2e412e | 2022-04-22 18:08:09 +0000 | [diff] [blame] | 414 | * Available since API level 34. |
Elliott Hughes | d4fd67c | 2022-11-30 19:53:33 +0000 | [diff] [blame] | 415 | * |
| 416 | * Returns the number of bytes copied on success, and returns -1 and sets |
| 417 | * `errno` on failure. |
zijunzhao | c2e412e | 2022-04-22 18:08:09 +0000 | [diff] [blame] | 418 | */ |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 419 | ssize_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); |
zijunzhao | c2e412e | 2022-04-22 18:08:09 +0000 | [diff] [blame] | 420 | |
Dan Albert | 2dbea43 | 2019-06-14 14:19:22 -0700 | [diff] [blame] | 421 | #if __ANDROID_API__ >= 28 |
zijunzhao | 3d59110 | 2023-01-10 00:18:05 +0000 | [diff] [blame] | 422 | void swab(const void* _Nonnull __src, void* _Nonnull __dst, ssize_t __byte_count) __INTRODUCED_IN(28); |
Dan Albert | 2dbea43 | 2019-06-14 14:19:22 -0700 | [diff] [blame] | 423 | #endif |
Elliott Hughes | fa386e0 | 2017-10-18 13:34:32 -0700 | [diff] [blame] | 424 | |
Maciej Żenczykowski | b65e105 | 2022-01-21 11:19:55 -0800 | [diff] [blame] | 425 | /** |
| 426 | * [close_range(2)](https://man7.org/linux/man-pages/man2/close_range.2.html) |
| 427 | * performs an action (which depends on value of flags) on an inclusive range |
| 428 | * of file descriptors. |
| 429 | * |
| 430 | * Available since API level 34. |
| 431 | * |
| 432 | * Note: there is no emulation on too old kernels, hence this will fail with |
| 433 | * -1/ENOSYS on pre-5.9 kernels, -1/EINVAL for unsupported flags. In particular |
| 434 | * CLOSE_RANGE_CLOEXEC requires 5.11, though support was backported to Android |
| 435 | * Common Kernel 5.10-T. |
| 436 | * |
| 437 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 438 | */ |
| 439 | int close_range(unsigned int __min_fd, unsigned int __max_fd, int __flags) __INTRODUCED_IN(34); |
| 440 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 441 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 442 | #define _UNISTD_H_ |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 443 | #include <bits/fortify/unistd.h> |
Elliott Hughes | 9c60177 | 2018-08-28 12:17:20 -0700 | [diff] [blame] | 444 | #undef _UNISTD_H_ |
George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 445 | #endif |
Daniel Micay | 9101b00 | 2015-05-20 15:31:26 -0400 | [diff] [blame] | 446 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 447 | __END_DECLS |
Dan Albert | 2dbea43 | 2019-06-14 14:19:22 -0700 | [diff] [blame] | 448 | |
| 449 | #include <android/legacy_unistd_inlines.h> |