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 | */ |
| 28 | #ifndef _UNISTD_H_ |
| 29 | #define _UNISTD_H_ |
| 30 | |
| 31 | #include <stddef.h> |
| 32 | #include <sys/cdefs.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/select.h> |
| 35 | #include <sys/sysconf.h> |
| 36 | #include <linux/capability.h> |
| 37 | #include <pathconf.h> |
| 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
| 41 | /* Standard file descriptor numbers. */ |
| 42 | #define STDIN_FILENO 0 |
| 43 | #define STDOUT_FILENO 1 |
| 44 | #define STDERR_FILENO 2 |
| 45 | |
| 46 | /* Values for whence in fseek and lseek */ |
| 47 | #define SEEK_SET 0 |
| 48 | #define SEEK_CUR 1 |
| 49 | #define SEEK_END 2 |
| 50 | |
| 51 | extern char **environ; |
| 52 | extern __noreturn void _exit(int); |
| 53 | |
| 54 | extern pid_t fork(void); |
| 55 | extern pid_t vfork(void); |
| 56 | extern pid_t getpid(void); |
| 57 | extern pid_t gettid(void); |
| 58 | extern pid_t getpgid(pid_t); |
| 59 | extern int setpgid(pid_t, pid_t); |
| 60 | extern pid_t getppid(void); |
| 61 | extern pid_t getpgrp(void); |
| 62 | extern int setpgrp(void); |
| 63 | extern pid_t setsid(void); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 64 | |
| 65 | extern int execv(const char *, char * const *); |
| 66 | extern int execvp(const char *, char * const *); |
| 67 | extern int execve(const char *, char * const *, char * const *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | extern int execl(const char *, const char *, ...); |
| 69 | extern int execlp(const char *, const char *, ...); |
| 70 | extern int execle(const char *, const char *, ...); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 72 | extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); |
| 73 | extern int prctl(int option, unsigned long arg2, unsigned long arg3, |
| 74 | unsigned long arg4, unsigned long arg5); |
| 75 | |
| 76 | extern int nice(int); |
| 77 | |
| 78 | extern int setuid(uid_t); |
| 79 | extern uid_t getuid(void); |
| 80 | extern int seteuid(uid_t); |
| 81 | extern uid_t geteuid(void); |
| 82 | extern int setgid(gid_t); |
| 83 | extern gid_t getgid(void); |
| 84 | extern int setegid(gid_t); |
| 85 | extern gid_t getegid(void); |
| 86 | extern int getgroups(int, gid_t *); |
| 87 | extern int setgroups(size_t, const gid_t *); |
| 88 | extern int setreuid(uid_t, uid_t); |
| 89 | extern int setregid(gid_t, gid_t); |
| 90 | extern int setresuid(uid_t, uid_t, uid_t); |
| 91 | extern int setresgid(gid_t, gid_t, gid_t); |
| 92 | extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid); |
| 93 | 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] | 94 | extern int issetugid(void); |
| 95 | extern char* getlogin(void); |
Colin Cross | fc10b24 | 2010-01-13 17:48:34 -0800 | [diff] [blame] | 96 | extern char* getusershell(void); |
| 97 | extern void setusershell(void); |
| 98 | extern void endusershell(void); |
| 99 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 100 | |
| 101 | |
| 102 | /* Macros for access() */ |
| 103 | #define R_OK 4 /* Read */ |
| 104 | #define W_OK 2 /* Write */ |
| 105 | #define X_OK 1 /* Execute */ |
| 106 | #define F_OK 0 /* Existence */ |
| 107 | |
| 108 | extern int access(const char *, int); |
| 109 | extern int link(const char *, const char *); |
| 110 | extern int unlink(const char *); |
| 111 | extern int chdir(const char *); |
| 112 | extern int fchdir(int); |
| 113 | extern int rmdir(const char *); |
| 114 | extern int pipe(int *); |
David 'Digit' Turner | 275cd48 | 2010-09-27 17:33:08 +0200 | [diff] [blame] | 115 | #ifdef _GNU_SOURCE /* GLibc compatibility */ |
| 116 | extern int pipe2(int *, int); |
| 117 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 118 | extern int chroot(const char *); |
| 119 | extern int symlink(const char *, const char *); |
| 120 | extern int readlink(const char *, char *, size_t); |
| 121 | extern int chown(const char *, uid_t, gid_t); |
| 122 | extern int fchown(int, uid_t, gid_t); |
| 123 | extern int lchown(const char *, uid_t, gid_t); |
David 'Digit' Turner | da3019b | 2010-06-11 14:37:34 -0700 | [diff] [blame] | 124 | extern int truncate(const char *, off_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 125 | extern char *getcwd(char *, size_t); |
| 126 | |
| 127 | extern int sync(void); |
| 128 | |
| 129 | extern int close(int); |
| 130 | extern off_t lseek(int, off_t, int); |
| 131 | extern loff_t lseek64(int, loff_t, int); |
| 132 | |
| 133 | extern ssize_t read(int, void *, size_t); |
| 134 | extern ssize_t write(int, const void *, size_t); |
| 135 | extern ssize_t pread(int, void *, size_t, off_t); |
| 136 | extern ssize_t pwrite(int, void *, size_t, off_t); |
| 137 | |
| 138 | extern int dup(int); |
| 139 | extern int dup2(int, int); |
| 140 | extern int fcntl(int, int, ...); |
| 141 | extern int ioctl(int, int, ...); |
| 142 | extern int flock(int, int); |
| 143 | extern int fsync(int); |
| 144 | extern int fdatasync(int); |
| 145 | extern int ftruncate(int, off_t); |
| 146 | |
| 147 | extern int pause(void); |
| 148 | extern unsigned int alarm(unsigned int); |
| 149 | extern unsigned int sleep(unsigned int); |
Elliott Hughes | 99d7907 | 2009-12-14 17:07:19 -0800 | [diff] [blame] | 150 | extern int usleep(unsigned long); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 151 | |
| 152 | extern int gethostname(char *, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 153 | |
| 154 | extern int getdtablesize(void); |
| 155 | |
| 156 | extern void *__brk(void *); |
| 157 | extern int brk(void *); |
| 158 | extern void *sbrk(ptrdiff_t); |
| 159 | |
| 160 | extern int getopt(int, char * const *, const char *); |
| 161 | extern char *optarg; |
| 162 | extern int optind, opterr, optopt; |
| 163 | |
| 164 | extern int isatty(int); |
Colin Cross | fc10b24 | 2010-01-13 17:48:34 -0800 | [diff] [blame] | 165 | extern char* ttyname(int); |
| 166 | extern int ttyname_r(int, char*, size_t); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 167 | |
| 168 | extern int acct(const char* filepath); |
| 169 | |
| 170 | static __inline__ int getpagesize(void) { |
| 171 | extern unsigned int __page_size; |
| 172 | return __page_size; |
| 173 | } |
| 174 | static __inline__ int __getpageshift(void) { |
| 175 | extern unsigned int __page_shift; |
| 176 | return __page_shift; |
| 177 | } |
| 178 | |
| 179 | extern int sysconf(int name); |
| 180 | |
| 181 | extern int daemon(int, int); |
| 182 | |
| 183 | /* A special syscall that is only available on the ARM, not x86 function. */ |
| 184 | extern int cacheflush(long start, long end, long flags); |
| 185 | |
| 186 | extern pid_t tcgetpgrp(int fd); |
| 187 | extern int tcsetpgrp(int fd, pid_t _pid); |
| 188 | |
David 'Digit' Turner | bb5581a | 2010-10-09 17:56:55 +0200 | [diff] [blame^] | 189 | #if 0 /* MISSING FROM BIONIC */ |
| 190 | extern pid_t getsid(pid_t); |
| 191 | extern int execvpe(const char *, char * const *, char * const *); |
| 192 | extern int execlpe(const char *, const char *, ...); |
| 193 | extern int getfsuid(uid_t); |
| 194 | extern int setfsuid(uid_t); |
| 195 | extern int getlogin_r(char* name, size_t namesize); |
| 196 | extern int sethostname(const char *, size_t); |
| 197 | extern int getdomainname(char *, size_t); |
| 198 | extern int setdomainname(const char *, size_t); |
| 199 | #endif /* MISSING */ |
| 200 | |
Elliott Hughes | cf399f7 | 2009-10-05 13:19:05 -0700 | [diff] [blame] | 201 | /* Used to retry syscalls that can return EINTR. */ |
| 202 | #define TEMP_FAILURE_RETRY(exp) ({ \ |
| 203 | typeof (exp) _rc; \ |
| 204 | do { \ |
| 205 | _rc = (exp); \ |
| 206 | } while (_rc == -1 && errno == EINTR); \ |
| 207 | _rc; }) |
| 208 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 209 | __END_DECLS |
| 210 | |
| 211 | #endif /* _UNISTD_H_ */ |