blob: ef75c84309ec8331fd44f802d8e3c8f31a2a2a3e [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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _UNISTD_H_
30#define _UNISTD_H_
31
32#include <stddef.h>
33#include <sys/cdefs.h>
34#include <sys/types.h>
35#include <sys/select.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036
Josh Gaoee8d1692016-04-07 14:16:30 -070037#include <bits/fcntl.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
Elliott Hughes58d9e282014-04-22 17:41:00 -070077extern char** environ;
78
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 Hughes3b2096a2016-07-22 18:57:12 -070081pid_t fork(void);
82pid_t vfork(void);
83pid_t getpid(void);
Elliott Hughes95fa0612016-09-28 12:29:52 -070084pid_t gettid(void) __attribute_const__;
Elliott Hughes3b2096a2016-07-22 18:57:12 -070085pid_t getpgid(pid_t __pid);
86int setpgid(pid_t __pid, pid_t __pgid);
87pid_t getppid(void);
88pid_t getpgrp(void);
89int setpgrp(void);
90pid_t getsid(pid_t __pid) __INTRODUCED_IN(17);
91pid_t setsid(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092
Elliott Hughes3b2096a2016-07-22 18:57:12 -070093int execv(const char* __path, char* const* __argv);
94int execvp(const char* __file, char* const* __argv);
95int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21);
96int execve(const char* __file, char* const* __argv, char* const* __envp);
Josh Gaod80a52e2016-08-10 15:18:29 -070097int execl(const char* __path, const char* __arg0, ...) __attribute__((__sentinel__));
98int execlp(const char* __file, const char* __arg0, ...) __attribute__((__sentinel__));
99int execle(const char* __path, const char* __arg0, ... /*, char* const* __envp */)
100 __attribute__((__sentinel__(1)));
Elliott Hughes4d215aa2017-10-18 15:54:56 -0700101int fexecve(int __fd, char* const* __argv, char* const* __envp) __INTRODUCED_IN_FUTURE;
David 'Digit' Turnerb083bb52011-05-26 02:46:41 +0200102
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700103int nice(int __incr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800104
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700105int setuid(uid_t __uid);
106uid_t getuid(void);
107int seteuid(uid_t __uid);
108uid_t geteuid(void);
109int setgid(gid_t __gid);
110gid_t getgid(void);
111int setegid(gid_t __gid);
112gid_t getegid(void);
113int getgroups(int __size, gid_t* __list);
114int setgroups(size_t __size, const gid_t* __list);
115int setreuid(uid_t __ruid, uid_t __euid);
116int setregid(gid_t __rgid, gid_t __egid);
117int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
118int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
119int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
120int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
121char* getlogin(void);
Elliott Hughes06bd5862017-07-28 16:27:49 -0700122int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN_FUTURE;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800123
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700124long fpathconf(int __fd, int __name);
125long pathconf(const char* __path, int __name);
Elliott Hughesa186b2e2014-09-22 14:49:07 -0700126
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700127int access(const char* __path, int __mode);
128int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700129int link(const char* __old_path, const char* __new_path);
130int 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 -0700131int unlink(const char* __path);
132int unlinkat(int __dirfd, const char* __path, int __flags);
133int chdir(const char* __path);
134int fchdir(int __fd);
135int rmdir(const char* __path);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700136int pipe(int __fds[2]);
Elliott Hughes5f5cc452014-08-18 16:04:03 -0700137#if defined(__USE_GNU)
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700138int pipe2(int __fds[2], int __flags) __INTRODUCED_IN(9);
David 'Digit' Turner275cd482010-09-27 17:33:08 +0200139#endif
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700140int chroot(const char* __path);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700141int symlink(const char* __old_path, const char* __new_path);
142int symlinkat(const char* __old_path, int __new_dir_fd, const char* __new_path) __INTRODUCED_IN(21);
143ssize_t readlink(const char* __path, char* __buf, size_t __buf_size)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800144 __overloadable __RENAME_CLANG(readlink);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700145ssize_t readlinkat(int __dir_fd, const char* __path, char* __buf, size_t __buf_size)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800146 __INTRODUCED_IN(21) __overloadable __RENAME_CLANG(readlinkat);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700147int chown(const char* __path, uid_t __owner, gid_t __group);
148int fchown(int __fd, uid_t __owner, gid_t __group);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700149int fchownat(int __dir_fd, const char* __path, uid_t __owner, gid_t __group, int __flags);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700150int lchown(const char* __path, uid_t __owner, gid_t __group);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800151char* getcwd(char* __buf, size_t __size) __overloadable __RENAME_CLANG(getcwd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800152
Elliott Hughes79a8f4b2016-11-29 15:16:08 -0800153void sync(void);
Elliott Hughes896362e2017-08-24 16:31:49 -0700154#if defined(__USE_GNU)
155int syncfs(int __fd) __INTRODUCED_IN_FUTURE;
156#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800157
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700158int close(int __fd);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800159
George Burgess IV7cc779f2017-02-09 00:00:31 -0800160ssize_t read(int __fd, void* __buf, size_t __count) __overloadable
161 __RENAME_CLANG(read);
162ssize_t write(int __fd, const void* __buf, size_t __count) __overloadable
163 __RENAME_CLANG(write);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800164
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700165int dup(int __old_fd);
166int dup2(int __old_fd, int __new_fd);
167int dup3(int __old_fd, int __new_fd, int __flags) __INTRODUCED_IN(21);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700168int fsync(int __fd);
169int fdatasync(int __fd) __INTRODUCED_IN(9);
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800170
Elliott Hughesa3481742017-11-28 14:47:17 -0800171/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */
Elliott Hughes00fedf52017-07-05 15:23:50 -0700172#if defined(__USE_FILE_OFFSET64)
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700173int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
Elliott Hughesa3481742017-11-28 14:47:17 -0800174off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800175ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
176 __overloadable __RENAME(pread64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700177ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800178 __overloadable __RENAME(pwrite64) __INTRODUCED_IN(12);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700179int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
Dan Albertaf4713e2015-09-04 12:59:53 -0700180#else
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700181int truncate(const char* __path, off_t __length);
Elliott Hughesa3481742017-11-28 14:47:17 -0800182off_t lseek(int __fd, off_t __offset, int __whence);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800183ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
184 __overloadable __RENAME_CLANG(pread);
185ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
186 __overloadable __RENAME_CLANG(pwrite);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700187int ftruncate(int __fd, off_t __length);
Dan Albertaf4713e2015-09-04 12:59:53 -0700188#endif
189
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700190int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
Elliott Hughesa3481742017-11-28 14:47:17 -0800191off64_t lseek64(int __fd, off64_t __offset, int __whence);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800192ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset)
193 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pread64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700194ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800195 __INTRODUCED_IN(12) __overloadable __RENAME_CLANG(pwrite64);
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700196int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800197
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700198int pause(void);
199unsigned int alarm(unsigned int __seconds);
200unsigned int sleep(unsigned int __seconds);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700201int usleep(useconds_t __microseconds);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800202
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700203int gethostname(char* __buf, size_t __buf_size);
204int sethostname(const char* __name, size_t __n) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800205
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700206int brk(void* __addr);
207void* sbrk(ptrdiff_t __increment);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800208
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700209int isatty(int __fd);
210char* ttyname(int __fd);
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700211int ttyname_r(int __fd, char* __buf, size_t __buf_size) __INTRODUCED_IN(8);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800212
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700213int acct(const char* __path);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800214
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800215#if __ANDROID_API__ >= __ANDROID_API_L__
Josh Gaob6a4a4c2016-07-26 16:34:40 -0700216int getpagesize(void) __INTRODUCED_IN(21);
Dan Albertaf4713e2015-09-04 12:59:53 -0700217#else
Dan Alberta39f5d82016-09-14 17:10:26 -0700218static __inline__ int getpagesize(void) {
Dan Albertaf4713e2015-09-04 12:59:53 -0700219 return sysconf(_SC_PAGESIZE);
220}
221#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800222
Dan Albertaf4713e2015-09-04 12:59:53 -0700223long syscall(long __number, ...);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800224
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700225int daemon(int __no_chdir, int __no_close);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800226
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800227#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700228int cacheflush(long __addr, long __nbytes, long __cache);
Elliott Hughesa6ecba42014-02-10 18:37:02 -0800229 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
230#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800231
Elliott Hughes3b2096a2016-07-22 18:57:12 -0700232pid_t tcgetpgrp(int __fd);
233int tcsetpgrp(int __fd, pid_t __pid);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800234
Elliott Hughescf399f72009-10-05 13:19:05 -0700235/* Used to retry syscalls that can return EINTR. */
236#define TEMP_FAILURE_RETRY(exp) ({ \
Dan Alberta7821b72014-05-21 20:33:28 -0700237 __typeof__(exp) _rc; \
Elliott Hughescf399f72009-10-05 13:19:05 -0700238 do { \
239 _rc = (exp); \
240 } while (_rc == -1 && errno == EINTR); \
241 _rc; })
242
Elliott Hughesbda6f3b2017-08-25 15:07:05 -0700243int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26);
244int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26);
Greg Hackmanne2faf072016-03-03 08:37:53 -0800245
Elliott Hughesfa386e02017-10-18 13:34:32 -0700246void swab(const void* __src, void* __dst, ssize_t __byte_count) __INTRODUCED_IN_FUTURE;
247
George Burgess IVb97049c2017-07-24 15:05:05 -0700248#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
249#include <bits/fortify/unistd.h>
George Burgess IV7cc779f2017-02-09 00:00:31 -0800250#endif
Daniel Micay9101b002015-05-20 15:31:26 -0400251
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800252__END_DECLS
253
254#endif /* _UNISTD_H_ */