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 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 37#include <bits/fcntl.h> 38#include <bits/getopt.h> 39#include <bits/ioctl.h> 40#include <bits/lockf.h> 41#include <bits/posix_limits.h> 42#include <bits/seek_constants.h> 43#include <bits/sysconf.h> 44 45__BEGIN_DECLS 46 47#define STDIN_FILENO 0 48#define STDOUT_FILENO 1 49#define STDERR_FILENO 2 50 51#define F_OK 0 52#define X_OK 1 53#define W_OK 2 54#define R_OK 4 55 56#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 77extern char** environ; 78 79__noreturn void _exit(int __status); 80 81pid_t fork(void); 82pid_t vfork(void); 83pid_t getpid(void); 84pid_t gettid(void) __attribute_const__; 85pid_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); 92 93int 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); 97int 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))); 101int fexecve(int __fd, char* const* __argv, char* const* __envp) __INTRODUCED_IN(28); 102 103int nice(int __incr); 104 105int 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); 122int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN(28); 123 124long fpathconf(int __fd, int __name); 125long pathconf(const char* __path, int __name); 126 127int access(const char* __path, int __mode); 128int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16); 129int 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); 131int 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); 136int pipe(int __fds[2]); 137#if defined(__USE_GNU) 138int pipe2(int __fds[2], int __flags) __INTRODUCED_IN(9); 139#endif 140int chroot(const char* __path); 141int 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); 144ssize_t readlinkat(int __dir_fd, const char* __path, char* __buf, size_t __buf_size) 145 __INTRODUCED_IN(21); 146int chown(const char* __path, uid_t __owner, gid_t __group); 147int fchown(int __fd, uid_t __owner, gid_t __group); 148int fchownat(int __dir_fd, const char* __path, uid_t __owner, gid_t __group, int __flags); 149int lchown(const char* __path, uid_t __owner, gid_t __group); 150char* getcwd(char* __buf, size_t __size); 151 152void sync(void); 153#if defined(__USE_GNU) 154int syncfs(int __fd) __INTRODUCED_IN(28); 155#endif 156 157int close(int __fd); 158 159ssize_t read(int __fd, void* __buf, size_t __count); 160ssize_t write(int __fd, const void* __buf, size_t __count); 161 162int dup(int __old_fd); 163int dup2(int __old_fd, int __new_fd); 164int dup3(int __old_fd, int __new_fd, int __flags) __INTRODUCED_IN(21); 165int fsync(int __fd); 166int fdatasync(int __fd) __INTRODUCED_IN(9); 167 168/* See https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md */ 169#if defined(__USE_FILE_OFFSET64) 170int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21); 171off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64); 172ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) 173 __RENAME(pread64) __INTRODUCED_IN(12); 174ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset) 175 __RENAME(pwrite64) __INTRODUCED_IN(12); 176int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12); 177#else 178int truncate(const char* __path, off_t __length); 179off_t lseek(int __fd, off_t __offset, int __whence); 180ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset); 181ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset); 182int ftruncate(int __fd, off_t __length); 183#endif 184 185int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21); 186off64_t lseek64(int __fd, off64_t __offset, int __whence); 187ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12); 188ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12); 189int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12); 190 191int pause(void); 192unsigned int alarm(unsigned int __seconds); 193unsigned int sleep(unsigned int __seconds); 194int usleep(useconds_t __microseconds); 195 196int gethostname(char* __buf, size_t __buf_size); 197int sethostname(const char* __name, size_t __n) __INTRODUCED_IN(23); 198 199int brk(void* __addr); 200void* sbrk(ptrdiff_t __increment); 201 202int isatty(int __fd); 203char* ttyname(int __fd); 204int ttyname_r(int __fd, char* __buf, size_t __buf_size) __INTRODUCED_IN(8); 205 206int acct(const char* __path); 207 208#if __ANDROID_API__ >= __ANDROID_API_L__ 209int getpagesize(void) __INTRODUCED_IN(21); 210#else 211static __inline__ int getpagesize(void) { 212 return sysconf(_SC_PAGESIZE); 213} 214#endif 215 216long syscall(long __number, ...); 217 218int daemon(int __no_chdir, int __no_close); 219 220#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__)) 221int cacheflush(long __addr, long __nbytes, long __cache); 222 /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */ 223#endif 224 225pid_t tcgetpgrp(int __fd); 226int tcsetpgrp(int __fd, pid_t __pid); 227 228/* Used to retry syscalls that can return EINTR. */ 229#define TEMP_FAILURE_RETRY(exp) ({ \ 230 __typeof__(exp) _rc; \ 231 do { \ 232 _rc = (exp); \ 233 } while (_rc == -1 && errno == EINTR); \ 234 _rc; }) 235 236int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26); 237int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26); 238 239void swab(const void* __src, void* __dst, ssize_t __byte_count) __INTRODUCED_IN(28); 240 241#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) 242#include <bits/fortify/unistd.h> 243#endif 244 245__END_DECLS 246 247#endif 248