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 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #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> |
| 36 | #include <sys/sysconf.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | |
| 38 | __BEGIN_DECLS |
| 39 | |
| 40 | /* Standard file descriptor numbers. */ |
| 41 | #define STDIN_FILENO 0 |
| 42 | #define STDOUT_FILENO 1 |
| 43 | #define STDERR_FILENO 2 |
| 44 | |
| 45 | /* Values for whence in fseek and lseek */ |
| 46 | #define SEEK_SET 0 |
| 47 | #define SEEK_CUR 1 |
| 48 | #define SEEK_END 2 |
| 49 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 50 | #define _PC_FILESIZEBITS 0 |
| 51 | #define _PC_LINK_MAX 1 |
| 52 | #define _PC_MAX_CANON 2 |
| 53 | #define _PC_MAX_INPUT 3 |
| 54 | #define _PC_NAME_MAX 4 |
| 55 | #define _PC_PATH_MAX 5 |
| 56 | #define _PC_PIPE_BUF 6 |
| 57 | #define _PC_2_SYMLINKS 7 |
| 58 | #define _PC_ALLOC_SIZE_MIN 8 |
| 59 | #define _PC_REC_INCR_XFER_SIZE 9 |
| 60 | #define _PC_REC_MAX_XFER_SIZE 10 |
| 61 | #define _PC_REC_MIN_XFER_SIZE 11 |
| 62 | #define _PC_REC_XFER_ALIGN 12 |
| 63 | #define _PC_SYMLINK_MAX 13 |
| 64 | #define _PC_CHOWN_RESTRICTED 14 |
| 65 | #define _PC_NO_TRUNC 15 |
| 66 | #define _PC_VDISABLE 16 |
| 67 | #define _PC_ASYNC_IO 17 |
| 68 | #define _PC_PRIO_IO 18 |
| 69 | #define _PC_SYNC_IO 19 |
| 70 | |
| 71 | #include <machine/posix_limits.h> |
| 72 | |
Elliott Hughes | 58d9e28 | 2014-04-22 17:41:00 -0700 | [diff] [blame] | 73 | extern char** environ; |
| 74 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 75 | extern __noreturn void _exit(int); |
| 76 | |
| 77 | extern pid_t fork(void); |
| 78 | extern pid_t vfork(void); |
| 79 | extern pid_t getpid(void); |
Elliott Hughes | b27a840 | 2014-06-10 20:47:49 -0700 | [diff] [blame] | 80 | extern pid_t gettid(void) __pure2; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | extern pid_t getpgid(pid_t); |
| 82 | extern int setpgid(pid_t, pid_t); |
| 83 | extern pid_t getppid(void); |
| 84 | extern pid_t getpgrp(void); |
| 85 | extern int setpgrp(void); |
Irina Tirdea | 1ad10a5 | 2012-08-29 11:48:35 +0300 | [diff] [blame] | 86 | extern pid_t getsid(pid_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | extern pid_t setsid(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 | |
| 89 | extern int execv(const char *, char * const *); |
| 90 | extern int execvp(const char *, char * const *); |
Elliott Hughes | 0133944 | 2014-02-20 18:04:58 -0800 | [diff] [blame] | 91 | extern int execvpe(const char *, char * const *, char * const *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | extern int execve(const char *, char * const *, char * const *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 93 | extern int execl(const char *, const char *, ...); |
| 94 | extern int execlp(const char *, const char *, ...); |
| 95 | extern int execle(const char *, const char *, ...); |
David 'Digit' Turner | b083bb5 | 2011-05-26 02:46:41 +0200 | [diff] [blame] | 96 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | extern int nice(int); |
| 98 | |
| 99 | extern int setuid(uid_t); |
| 100 | extern uid_t getuid(void); |
| 101 | extern int seteuid(uid_t); |
| 102 | extern uid_t geteuid(void); |
| 103 | extern int setgid(gid_t); |
| 104 | extern gid_t getgid(void); |
| 105 | extern int setegid(gid_t); |
| 106 | extern gid_t getegid(void); |
| 107 | extern int getgroups(int, gid_t *); |
| 108 | extern int setgroups(size_t, const gid_t *); |
| 109 | extern int setreuid(uid_t, uid_t); |
| 110 | extern int setregid(gid_t, gid_t); |
| 111 | extern int setresuid(uid_t, uid_t, uid_t); |
| 112 | extern int setresgid(gid_t, gid_t, gid_t); |
| 113 | extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid); |
| 114 | extern int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 115 | extern char* getlogin(void); |
Colin Cross | fc10b24 | 2010-01-13 17:48:34 -0800 | [diff] [blame] | 116 | extern char* getusershell(void); |
| 117 | extern void setusershell(void); |
| 118 | extern void endusershell(void); |
| 119 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 120 | |
Elliott Hughes | a186b2e | 2014-09-22 14:49:07 -0700 | [diff] [blame] | 121 | extern long fpathconf(int, int); |
| 122 | extern long pathconf(const char*, int); |
| 123 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 124 | |
| 125 | /* Macros for access() */ |
| 126 | #define R_OK 4 /* Read */ |
| 127 | #define W_OK 2 /* Write */ |
| 128 | #define X_OK 1 /* Execute */ |
| 129 | #define F_OK 0 /* Existence */ |
| 130 | |
Elliott Hughes | f8fcfbc | 2013-10-22 13:28:46 -0700 | [diff] [blame] | 131 | extern int access(const char*, int); |
| 132 | extern int faccessat(int, const char*, int, int); |
| 133 | extern int link(const char*, const char*); |
| 134 | extern int linkat(int, const char*, int, const char*, int); |
| 135 | extern int unlink(const char*); |
| 136 | extern int unlinkat(int, const char*, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 137 | extern int chdir(const char *); |
| 138 | extern int fchdir(int); |
| 139 | extern int rmdir(const char *); |
| 140 | extern int pipe(int *); |
Elliott Hughes | 5f5cc45 | 2014-08-18 16:04:03 -0700 | [diff] [blame] | 141 | #if defined(__USE_GNU) |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 142 | extern int pipe2(int *, int); |
| 143 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 144 | extern int chroot(const char *); |
Elliott Hughes | f8fcfbc | 2013-10-22 13:28:46 -0700 | [diff] [blame] | 145 | extern int symlink(const char*, const char*); |
| 146 | extern int symlinkat(const char*, int, const char*); |
| 147 | extern ssize_t readlink(const char*, char*, size_t); |
| 148 | extern ssize_t readlinkat(int, const char*, char*, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 149 | extern int chown(const char *, uid_t, gid_t); |
| 150 | extern int fchown(int, uid_t, gid_t); |
Elliott Hughes | f8fcfbc | 2013-10-22 13:28:46 -0700 | [diff] [blame] | 151 | extern int fchownat(int, const char*, uid_t, gid_t, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 152 | extern int lchown(const char *, uid_t, gid_t); |
David 'Digit' Turner | da3019b | 2010-06-11 14:37:34 -0700 | [diff] [blame] | 153 | extern int truncate(const char *, off_t); |
Elliott Hughes | b4f7616 | 2013-09-19 16:27:24 -0700 | [diff] [blame] | 154 | extern int truncate64(const char *, off64_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 155 | extern char *getcwd(char *, size_t); |
| 156 | |
| 157 | extern int sync(void); |
| 158 | |
| 159 | extern int close(int); |
| 160 | extern off_t lseek(int, off_t, int); |
Dima Zavin | 6367364 | 2010-08-06 11:45:43 -0700 | [diff] [blame] | 161 | extern off64_t lseek64(int, off64_t, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 162 | |
| 163 | extern ssize_t read(int, void *, size_t); |
| 164 | extern ssize_t write(int, const void *, size_t); |
| 165 | extern ssize_t pread(int, void *, size_t, off_t); |
Kenny Root | 72e64e0 | 2010-11-24 13:10:49 -0800 | [diff] [blame] | 166 | extern ssize_t pread64(int, void *, size_t, off64_t); |
Jeff Hamilton | 2304a0b | 2010-08-11 11:28:26 -0500 | [diff] [blame] | 167 | extern ssize_t pwrite(int, const void *, size_t, off_t); |
Kenny Root | 72e64e0 | 2010-11-24 13:10:49 -0800 | [diff] [blame] | 168 | extern ssize_t pwrite64(int, const void *, size_t, off64_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 169 | |
| 170 | extern int dup(int); |
| 171 | extern int dup2(int, int); |
Elliott Hughes | cac7b9d | 2013-10-23 09:48:29 -0700 | [diff] [blame] | 172 | extern int dup3(int, int, int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 173 | extern int fcntl(int, int, ...); |
| 174 | extern int ioctl(int, int, ...); |
| 175 | extern int flock(int, int); |
| 176 | extern int fsync(int); |
| 177 | extern int fdatasync(int); |
| 178 | extern int ftruncate(int, off_t); |
David 'Digit' Turner | 95d751f | 2010-12-16 16:47:14 +0100 | [diff] [blame] | 179 | extern int ftruncate64(int, off64_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 180 | |
| 181 | extern int pause(void); |
| 182 | extern unsigned int alarm(unsigned int); |
| 183 | extern unsigned int sleep(unsigned int); |
Elliott Hughes | ab61eb3 | 2013-11-20 16:09:06 -0800 | [diff] [blame] | 184 | extern int usleep(useconds_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 185 | |
Elliott Hughes | b86a4c7 | 2014-11-07 16:07:13 -0800 | [diff] [blame] | 186 | int gethostname(char*, size_t); |
| 187 | int sethostname(const char*, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 188 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 189 | extern void *__brk(void *); |
| 190 | extern int brk(void *); |
| 191 | extern void *sbrk(ptrdiff_t); |
| 192 | |
| 193 | extern int getopt(int, char * const *, const char *); |
| 194 | extern char *optarg; |
| 195 | extern int optind, opterr, optopt; |
| 196 | |
| 197 | extern int isatty(int); |
Elliott Hughes | a381fe8 | 2014-12-09 20:30:23 -0800 | [diff] [blame] | 198 | extern char* ttyname(int); |
Colin Cross | fc10b24 | 2010-01-13 17:48:34 -0800 | [diff] [blame] | 199 | extern int ttyname_r(int, char*, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 200 | |
| 201 | extern int acct(const char* filepath); |
| 202 | |
Bernhard Rosenkraenzer | 9ae59c0 | 2013-09-18 23:29:08 +0200 | [diff] [blame] | 203 | int getpagesize(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 204 | |
Elliott Hughes | 60d84af | 2014-11-14 15:14:44 -0800 | [diff] [blame] | 205 | long sysconf(int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 206 | |
| 207 | extern int daemon(int, int); |
| 208 | |
Elliott Hughes | a6ecba4 | 2014-02-10 18:37:02 -0800 | [diff] [blame] | 209 | #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) |
| 210 | extern int cacheflush(long, long, long); |
| 211 | /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ |
| 212 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 213 | |
| 214 | extern pid_t tcgetpgrp(int fd); |
| 215 | extern int tcsetpgrp(int fd, pid_t _pid); |
| 216 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 217 | /* Used to retry syscalls that can return EINTR. */ |
| 218 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
Dan Albert | a7821b7 | 2014-05-21 20:33:28 -0700 | [diff] [blame] | 219 | __typeof__(exp) _rc; \ |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 220 | do { \ |
| 221 | _rc = (exp); \ |
| 222 | } while (_rc == -1 && errno == EINTR); \ |
| 223 | _rc; }) |
| 224 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 225 | extern ssize_t __read_chk(int, void*, size_t, size_t); |
| 226 | __errordecl(__read_dest_size_error, "read called with size bigger than destination"); |
| 227 | __errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); |
Elliott Hughes | 2cfb4e8 | 2014-08-18 14:45:42 -0700 | [diff] [blame] | 228 | extern ssize_t __read_real(int, void*, size_t) __RENAME(read); |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 229 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 230 | #if defined(__BIONIC_FORTIFY) |
| 231 | |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 232 | __BIONIC_FORTIFY_INLINE |
| 233 | ssize_t read(int fd, void* buf, size_t count) { |
| 234 | size_t bos = __bos0(buf); |
| 235 | |
| 236 | #if !defined(__clang__) |
| 237 | if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { |
| 238 | __read_count_toobig_error(); |
| 239 | } |
| 240 | |
| 241 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 242 | return __read_real(fd, buf, count); |
| 243 | } |
| 244 | |
| 245 | if (__builtin_constant_p(count) && (count > bos)) { |
| 246 | __read_dest_size_error(); |
| 247 | } |
| 248 | |
| 249 | if (__builtin_constant_p(count) && (count <= bos)) { |
| 250 | return __read_real(fd, buf, count); |
| 251 | } |
| 252 | #endif |
| 253 | |
| 254 | return __read_chk(fd, buf, count, bos); |
| 255 | } |
| 256 | #endif /* defined(__BIONIC_FORTIFY) */ |
| 257 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 258 | __END_DECLS |
| 259 | |
| 260 | #endif /* _UNISTD_H_ */ |