blob: f142525ba934b67d89b10f767e835cd0af9db596 [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>
Josh Gao7449e592016-04-07 16:37:49 -070037#include <bits/getopt.h>
Josh Gao98e574c2016-04-07 14:19:03 -070038#include <bits/ioctl.h>
Elliott Hughes5704c422016-01-25 18:06:24 -080039#include <bits/lockf.h>
40#include <bits/posix_limits.h>
Elliott Hughesfd936ae2016-08-12 10:16:34 -070041#include <bits/seek_constants.h>
Josh Gao8c8ef592016-04-07 16:33:30 -070042#include <bits/sysconf.h>
Elliott Hughes1ed337d2015-02-02 14:02:09 -080043
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044__BEGIN_DECLS
45
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046#define STDIN_FILENO 0
47#define STDOUT_FILENO 1
48#define STDERR_FILENO 2
49
Elliott Hughes1ed337d2015-02-02 14:02:09 -080050#define F_OK 0
51#define X_OK 1
52#define W_OK 2
53#define R_OK 4
54
Elliott Hughesa186b2e2014-09-22 14:49:07 -070055#define _PC_FILESIZEBITS 0
56#define _PC_LINK_MAX 1
57#define _PC_MAX_CANON 2
58#define _PC_MAX_INPUT 3
59#define _PC_NAME_MAX 4
60#define _PC_PATH_MAX 5
61#define _PC_PIPE_BUF 6
62#define _PC_2_SYMLINKS 7
63#define _PC_ALLOC_SIZE_MIN 8
64#define _PC_REC_INCR_XFER_SIZE 9
65#define _PC_REC_MAX_XFER_SIZE 10
66#define _PC_REC_MIN_XFER_SIZE 11
67#define _PC_REC_XFER_ALIGN 12
68#define _PC_SYMLINK_MAX 13
69#define _PC_CHOWN_RESTRICTED 14
70#define _PC_NO_TRUNC 15
71#define _PC_VDISABLE 16
72#define _PC_ASYNC_IO 17
73#define _PC_PRIO_IO 18
74#define _PC_SYNC_IO 19
75
Elliott Hughes58d9e282014-04-22 17:41:00 -070076extern char** environ;
77
Elliott Hughes3b2096a2016-07-22 18:57:12 -070078__noreturn void _exit(int __status);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079
Elliott Hughes3b2096a2016-07-22 18:57:12 -070080pid_t fork(void);
Josh Gao34033152019-05-13 13:15:50 -070081pid_t vfork(void) __returns_twice;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070082pid_t getpid(void);
Elliott Hughes95fa0612016-09-28 12:29:52 -070083pid_t gettid(void) __attribute_const__;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070084pid_t getpgid(pid_t __pid);
85int setpgid(pid_t __pid, pid_t __pgid);
86pid_t getppid(void);
87pid_t getpgrp(void);
88int setpgrp(void);
89pid_t getsid(pid_t __pid) __INTRODUCED_IN(17);
90pid_t setsid(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091
Elliott Hughes3b2096a2016-07-22 18:57:12 -070092int execv(const char* __path, char* const* __argv);
93int execvp(const char* __file, char* const* __argv);
94int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21);
95int execve(const char* __file, char* const* __argv, char* const* __envp);
Josh Gaod80a52e2016-08-10 15:18:29 -070096int execl(const char* __path, const char* __arg0, ...) __attribute__((__sentinel__));
97int execlp(const char* __file, const char* __arg0, ...) __attribute__((__sentinel__));
98int execle(const char* __path, const char* __arg0, ... /*, char* const* __envp */)
99 __attribute__((__sentinel__(1)));
Elliott Hughescc0fe6e2018-01-30 08:54:12 -0800100int fexecve(int __fd, char* const* __argv, char* const* __envp) __INTRODUCED_IN(28);
David 'Digit' Turnerb083bb52011-05-26 02:46:41 +0200101
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700102int nice(int __incr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800103
Elliott Hughes9c601772018-08-28 12:17:20 -0700104/**
105 * [setegid(2)](http://man7.org/linux/man-pages/man2/setegid.2.html) sets
106 * the effective group ID.
107 *
108 * On Android, this function only affects the calling thread, not all threads
109 * in the process.
110 *
111 * Returns 0 on success, and returns -1 and sets `errno` on failure.
112 */
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700113int setegid(gid_t __gid);
Elliott Hughes9c601772018-08-28 12:17:20 -0700114
115/**
116 * [seteuid(2)](http://man7.org/linux/man-pages/man2/seteuid.2.html) sets
117 * the effective user ID.
118 *
119 * On Android, this function only affects the calling thread, not all threads
120 * in the process.
121 *
122 * Returns 0 on success, and returns -1 and sets `errno` on failure.
123 */
124int seteuid(uid_t __uid);
125
126/**
127 * [setgid(2)](http://man7.org/linux/man-pages/man2/setgid.2.html) sets
128 * the group ID.
129 *
130 * On Android, this function only affects the calling thread, not all threads
131 * in the process.
132 *
133 * Returns 0 on success, and returns -1 and sets `errno` on failure.
134 */
135int setgid(gid_t __gid);
136
137/**
138 * [setregid(2)](http://man7.org/linux/man-pages/man2/setregid.2.html) sets
139 * the real and effective group IDs (use -1 to leave an ID unchanged).
140 *
141 * On Android, this function only affects the calling thread, not all threads
142 * in the process.
143 *
144 * Returns 0 on success, and returns -1 and sets `errno` on failure.
145 */
146int setregid(gid_t __rgid, gid_t __egid);
147
148/**
149 * [setresgid(2)](http://man7.org/linux/man-pages/man2/setresgid.2.html) sets
150 * the real, effective, and saved group IDs (use -1 to leave an ID unchanged).
151 *
152 * On Android, this function only affects the calling thread, not all threads
153 * in the process.
154 *
155 * Returns 0 on success, and returns -1 and sets `errno` on failure.
156 */
157int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
158
159/**
160 * [setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html) sets
161 * the real, effective, and saved user IDs (use -1 to leave an ID unchanged).
162 *
163 * On Android, this function only affects the calling thread, not all threads
164 * in the process.
165 *
166 * Returns 0 on success, and returns -1 and sets `errno` on failure.
167 */
168int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
169
170/**
171 * [setreuid(2)](http://man7.org/linux/man-pages/man2/setreuid.2.html) sets
172 * the real and effective group IDs (use -1 to leave an ID unchanged).
173 *
174 * On Android, this function only affects the calling thread, not all threads
175 * in the process.
176 *
177 * Returns 0 on success, and returns -1 and sets `errno` on failure.
178 */
179int setreuid(uid_t __ruid, uid_t __euid);
180
181/**
182 * [setuid(2)](http://man7.org/linux/man-pages/man2/setuid.2.html) sets
183 * the user ID.
184 *
185 * On Android, this function only affects the calling thread, not all threads
186 * in the process.
187 *
188 * Returns 0 on success, and returns -1 and sets `errno` on failure.
189 */
190int setuid(uid_t __uid);
191
192uid_t getuid(void);
193uid_t geteuid(void);
194gid_t getgid(void);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700195gid_t getegid(void);
196int getgroups(int __size, gid_t* __list);
197int setgroups(size_t __size, const gid_t* __list);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700198int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
199int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
200char* getlogin(void);
Elliott Hughescc0fe6e2018-01-30 08:54:12 -0800201int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800202
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700203long fpathconf(int __fd, int __name);
204long pathconf(const char* __path, int __name);
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700205
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700206int access(const char* __path, int __mode);
Elliott Hughes0e14c5a2019-10-03 20:35:38 -0700207int faccessat(int __dirfd, const char* __path, int __mode, int __flags);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700208int link(const char* __old_path, const char* __new_path);
209int linkat(int __old_dir_fd, const char* __old_path, int __new_dir_fd, const char* __new_path, int __flags) __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700210int unlink(const char* __path);
211int unlinkat(int __dirfd, const char* __path, int __flags);
212int chdir(const char* __path);
213int fchdir(int __fd);
214int rmdir(const char* __path);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700215int pipe(int __fds[2]);
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700216#if defined(__USE_GNU)
Elliott Hughesf106a392019-10-03 16:09:04 -0700217int pipe2(int __fds[2], int __flags);
David 'Digit' Turner275cd482010-09-27 17:33:08 +0200218#endif
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700219int chroot(const char* __path);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700220int symlink(const char* __old_path, const char* __new_path);
221int symlinkat(const char* __old_path, int __new_dir_fd, const char* __new_path) __INTRODUCED_IN(21);
George Burgess IV90242352018-02-06 12:51:31 -0800222ssize_t readlink(const char* __path, char* __buf, size_t __buf_size);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700223ssize_t readlinkat(int __dir_fd, const char* __path, char* __buf, size_t __buf_size)
George Burgess IV90242352018-02-06 12:51:31 -0800224 __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700225int chown(const char* __path, uid_t __owner, gid_t __group);
226int fchown(int __fd, uid_t __owner, gid_t __group);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700227int fchownat(int __dir_fd, const char* __path, uid_t __owner, gid_t __group, int __flags);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700228int lchown(const char* __path, uid_t __owner, gid_t __group);
George Burgess IV90242352018-02-06 12:51:31 -0800229char* getcwd(char* __buf, size_t __size);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800230
Elliott Hughes79a8f4b2016-11-29 15:16:08 -0800231void sync(void);
Elliott Hughes896362e2017-08-24 16:31:49 -0700232#if defined(__USE_GNU)
Elliott Hughescc0fe6e2018-01-30 08:54:12 -0800233int syncfs(int __fd) __INTRODUCED_IN(28);
Elliott Hughes896362e2017-08-24 16:31:49 -0700234#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800235
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700236int close(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800237
George Burgess IV90242352018-02-06 12:51:31 -0800238ssize_t read(int __fd, void* __buf, size_t __count);
239ssize_t write(int __fd, const void* __buf, size_t __count);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800240
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700241int dup(int __old_fd);
242int dup2(int __old_fd, int __new_fd);
243int dup3(int __old_fd, int __new_fd, int __flags) __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700244int fsync(int __fd);
Elliott Hughesf106a392019-10-03 16:09:04 -0700245int fdatasync(int __fd);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800246
Elliott Hughesa3481742017-11-28 14:47:17 -0800247/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
Elliott Hughes00fedf52017-07-05 15:23:50 -0700248#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700249int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
Elliott Hughesa3481742017-11-28 14:47:17 -0800250off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
Elliott Hughes0e14c5a2019-10-03 20:35:38 -0700251ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64);
252ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) __RENAME(pwrite64);
253int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64);
Dan Albertaf4713e2015-09-04 12:59:53 -0700254#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700255int truncate(const char* __path, off_t __length);
Elliott Hughesa3481742017-11-28 14:47:17 -0800256off_t lseek(int __fd, off_t __offset, int __whence);
George Burgess IV90242352018-02-06 12:51:31 -0800257ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
258ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700259int ftruncate(int __fd, off_t __length);
Dan Albertaf4713e2015-09-04 12:59:53 -0700260#endif
261
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700262int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
Elliott Hughesa3481742017-11-28 14:47:17 -0800263off64_t lseek64(int __fd, off64_t __offset, int __whence);
Elliott Hughes0e14c5a2019-10-03 20:35:38 -0700264ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset);
265ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset);
266int ftruncate64(int __fd, off64_t __length);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800267
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700268int pause(void);
269unsigned int alarm(unsigned int __seconds);
270unsigned int sleep(unsigned int __seconds);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700271int usleep(useconds_t __microseconds);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800272
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700273int gethostname(char* __buf, size_t __buf_size);
274int sethostname(const char* __name, size_t __n) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800275
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700276int brk(void* __addr);
277void* sbrk(ptrdiff_t __increment);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800278
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700279int isatty(int __fd);
280char* ttyname(int __fd);
Elliott Hughesf106a392019-10-03 16:09:04 -0700281int ttyname_r(int __fd, char* __buf, size_t __buf_size);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800282
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700283int acct(const char* __path);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800284
Elliott Hughes95c6cd72019-12-20 13:26:14 -0800285#if __ANDROID_API__ >= 21
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700286int getpagesize(void) __INTRODUCED_IN(21);
Dan Albertaf4713e2015-09-04 12:59:53 -0700287#else
Dan Alberta39f5d82016-09-14 17:10:26 -0700288static __inline__ int getpagesize(void) {
Dan Albertaf4713e2015-09-04 12:59:53 -0700289 return sysconf(_SC_PAGESIZE);
290}
291#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800292
Dan Albertaf4713e2015-09-04 12:59:53 -0700293long syscall(long __number, ...);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800294
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700295int daemon(int __no_chdir, int __no_close);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800296
Elliott Hughes5ac438e2020-02-13 15:56:31 -0800297#if defined(__arm__)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700298int cacheflush(long __addr, long __nbytes, long __cache);
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800299 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
300#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800301
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700302pid_t tcgetpgrp(int __fd);
303int tcsetpgrp(int __fd, pid_t __pid);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800304
Elliott Hughescf399f72009-10-05 13:19:05 -0700305/* Used to retry syscalls that can return EINTR. */
306#define TEMP_FAILURE_RETRY(exp) ({ \
Dan Alberta7821b72014-05-21 20:33:28 -0700307 __typeof__(exp) _rc; \
Elliott Hughescf399f72009-10-05 13:19:05 -0700308 do { \
309 _rc = (exp); \
310 } while (_rc == -1 && errno == EINTR); \
311 _rc; })
312
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700313int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26);
314int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26);
Greg Hackmanne2faf072016-03-03 08:37:53 -0800315
Dan Albert2dbea432019-06-14 14:19:22 -0700316#if __ANDROID_API__ >= 28
Elliott Hughescc0fe6e2018-01-30 08:54:12 -0800317void swab(const void* __src, void* __dst, ssize_t __byte_count) __INTRODUCED_IN(28);
Dan Albert2dbea432019-06-14 14:19:22 -0700318#endif
Elliott Hughesfa386e02017-10-18 13:34:32 -0700319
Maciej Żenczykowskib65e1052022-01-21 11:19:55 -0800320/**
321 * [close_range(2)](https://man7.org/linux/man-pages/man2/close_range.2.html)
322 * performs an action (which depends on value of flags) on an inclusive range
323 * of file descriptors.
324 *
325 * Available since API level 34.
326 *
327 * Note: there is no emulation on too old kernels, hence this will fail with
328 * -1/ENOSYS on pre-5.9 kernels, -1/EINVAL for unsupported flags. In particular
329 * CLOSE_RANGE_CLOEXEC requires 5.11, though support was backported to Android
330 * Common Kernel 5.10-T.
331 *
332 * Returns 0 on success, and returns -1 and sets `errno` on failure.
333 */
334int close_range(unsigned int __min_fd, unsigned int __max_fd, int __flags) __INTRODUCED_IN(34);
335
George Burgess IVb97049c2017-07-24 15:05:05 -0700336#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
Elliott Hughes9c601772018-08-28 12:17:20 -0700337#define _UNISTD_H_
George Burgess IVb97049c2017-07-24 15:05:05 -0700338#include <bits/fortify/unistd.h>
Elliott Hughes9c601772018-08-28 12:17:20 -0700339#undef _UNISTD_H_
George Burgess IV7cc779f2017-02-09 00:00:31 -0800340#endif
Daniel Micay9101b002015-05-20 15:31:26 -0400341
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800342__END_DECLS
Dan Albert2dbea432019-06-14 14:19:22 -0700343
344#include <android/legacy_unistd_inlines.h>