unistd.h revision 462abab12b074c62c0999859e65d5a32ebb41951
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 <pathconf.h> 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 50extern char** environ; 51 52extern __noreturn void _exit(int); 53 54extern pid_t fork(void); 55extern pid_t vfork(void); 56extern pid_t getpid(void); 57extern pid_t gettid(void) __pure2; 58extern pid_t getpgid(pid_t); 59extern int setpgid(pid_t, pid_t); 60extern pid_t getppid(void); 61extern pid_t getpgrp(void); 62extern int setpgrp(void); 63extern pid_t getsid(pid_t); 64extern pid_t setsid(void); 65 66extern int execv(const char *, char * const *); 67extern int execvp(const char *, char * const *); 68extern int execvpe(const char *, char * const *, char * const *); 69extern int execve(const char *, char * const *, char * const *); 70extern int execl(const char *, const char *, ...); 71extern int execlp(const char *, const char *, ...); 72extern int execle(const char *, const char *, ...); 73 74/* IMPORTANT: See comment under <sys/prctl.h> about this declaration */ 75extern int prctl(int option, ...); 76 77extern int nice(int); 78 79extern int setuid(uid_t); 80extern uid_t getuid(void); 81extern int seteuid(uid_t); 82extern uid_t geteuid(void); 83extern int setgid(gid_t); 84extern gid_t getgid(void); 85extern int setegid(gid_t); 86extern gid_t getegid(void); 87extern int getgroups(int, gid_t *); 88extern int setgroups(size_t, const gid_t *); 89extern int setreuid(uid_t, uid_t); 90extern int setregid(gid_t, gid_t); 91extern int setresuid(uid_t, uid_t, uid_t); 92extern int setresgid(gid_t, gid_t, gid_t); 93extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid); 94extern int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid); 95extern char* getlogin(void); 96extern char* getusershell(void); 97extern void setusershell(void); 98extern void endusershell(void); 99 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 108extern int access(const char*, int); 109extern int faccessat(int, const char*, int, int); 110extern int link(const char*, const char*); 111extern int linkat(int, const char*, int, const char*, int); 112extern int unlink(const char*); 113extern int unlinkat(int, const char*, int); 114extern int chdir(const char *); 115extern int fchdir(int); 116extern int rmdir(const char *); 117extern int pipe(int *); 118#ifdef _GNU_SOURCE 119extern int pipe2(int *, int); 120#endif 121extern int chroot(const char *); 122extern int symlink(const char*, const char*); 123extern int symlinkat(const char*, int, const char*); 124extern ssize_t readlink(const char*, char*, size_t); 125extern ssize_t readlinkat(int, const char*, char*, size_t); 126extern int chown(const char *, uid_t, gid_t); 127extern int fchown(int, uid_t, gid_t); 128extern int fchownat(int, const char*, uid_t, gid_t, int); 129extern int lchown(const char *, uid_t, gid_t); 130extern int truncate(const char *, off_t); 131extern int truncate64(const char *, off64_t); 132extern char *getcwd(char *, size_t); 133 134extern int sync(void); 135 136extern int close(int); 137extern off_t lseek(int, off_t, int); 138extern off64_t lseek64(int, off64_t, int); 139 140extern ssize_t read(int, void *, size_t); 141extern ssize_t write(int, const void *, size_t); 142extern ssize_t pread(int, void *, size_t, off_t); 143extern ssize_t pread64(int, void *, size_t, off64_t); 144extern ssize_t pwrite(int, const void *, size_t, off_t); 145extern ssize_t pwrite64(int, const void *, size_t, off64_t); 146 147extern int dup(int); 148extern int dup2(int, int); 149#ifdef _GNU_SOURCE 150extern int dup3(int, int, int); 151#endif 152extern int fcntl(int, int, ...); 153extern int ioctl(int, int, ...); 154extern int flock(int, int); 155extern int fsync(int); 156extern int fdatasync(int); 157extern int ftruncate(int, off_t); 158extern int ftruncate64(int, off64_t); 159 160extern int pause(void); 161extern unsigned int alarm(unsigned int); 162extern unsigned int sleep(unsigned int); 163extern int usleep(useconds_t); 164 165extern int gethostname(char *, size_t); 166 167extern void *__brk(void *); 168extern int brk(void *); 169extern void *sbrk(ptrdiff_t); 170 171extern int getopt(int, char * const *, const char *); 172extern char *optarg; 173extern int optind, opterr, optopt; 174 175extern int isatty(int); 176extern char* ttyname(int); 177extern int ttyname_r(int, char*, size_t); 178 179extern int acct(const char* filepath); 180 181int getpagesize(void); 182 183extern int sysconf(int name); 184 185extern int daemon(int, int); 186 187#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) 188extern int cacheflush(long, long, long); 189 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ 190#endif 191 192extern pid_t tcgetpgrp(int fd); 193extern int tcsetpgrp(int fd, pid_t _pid); 194 195#if 0 /* MISSING FROM BIONIC */ 196extern int execlpe(const char *, const char *, ...); 197extern int getfsuid(uid_t); 198extern int setfsuid(uid_t); 199extern int getlogin_r(char* name, size_t namesize); 200extern int sethostname(const char *, size_t); 201extern int getdomainname(char *, size_t); 202extern int setdomainname(const char *, size_t); 203#endif /* MISSING */ 204 205/* Used to retry syscalls that can return EINTR. */ 206#define TEMP_FAILURE_RETRY(exp) ({ \ 207 __typeof__(exp) _rc; \ 208 do { \ 209 _rc = (exp); \ 210 } while (_rc == -1 && errno == EINTR); \ 211 _rc; }) 212 213#if defined(__BIONIC_FORTIFY) 214extern ssize_t __read_chk(int, void*, size_t, size_t); 215__errordecl(__read_dest_size_error, "read called with size bigger than destination"); 216__errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX"); 217extern ssize_t __read_real(int, void*, size_t) 218 __asm__(__USER_LABEL_PREFIX__ "read"); 219 220__BIONIC_FORTIFY_INLINE 221ssize_t read(int fd, void* buf, size_t count) { 222 size_t bos = __bos0(buf); 223 224#if !defined(__clang__) 225 if (__builtin_constant_p(count) && (count > SSIZE_MAX)) { 226 __read_count_toobig_error(); 227 } 228 229 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 230 return __read_real(fd, buf, count); 231 } 232 233 if (__builtin_constant_p(count) && (count > bos)) { 234 __read_dest_size_error(); 235 } 236 237 if (__builtin_constant_p(count) && (count <= bos)) { 238 return __read_real(fd, buf, count); 239 } 240#endif 241 242 return __read_chk(fd, buf, count, bos); 243} 244#endif /* defined(__BIONIC_FORTIFY) */ 245 246__END_DECLS 247 248#endif /* _UNISTD_H_ */ 249