Home | History | Annotate | Download | only in include
      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 
     77 extern char** environ;
     78 
     79 __noreturn void _exit(int __status);
     80 
     81 pid_t  fork(void);
     82 pid_t  vfork(void);
     83 pid_t  getpid(void);
     84 pid_t  gettid(void) __attribute_const__;
     85 pid_t  getpgid(pid_t __pid);
     86 int    setpgid(pid_t __pid, pid_t __pgid);
     87 pid_t  getppid(void);
     88 pid_t  getpgrp(void);
     89 int    setpgrp(void);
     90 pid_t  getsid(pid_t __pid) __INTRODUCED_IN(17);
     91 pid_t  setsid(void);
     92 
     93 int execv(const char* __path, char* const* __argv);
     94 int execvp(const char* __file, char* const* __argv);
     95 int execvpe(const char* __file, char* const* __argv, char* const* __envp) __INTRODUCED_IN(21);
     96 int execve(const char* __file, char* const* __argv, char* const* __envp);
     97 int execl(const char* __path, const char* __arg0, ...) __attribute__((__sentinel__));
     98 int execlp(const char* __file, const char* __arg0, ...) __attribute__((__sentinel__));
     99 int execle(const char* __path, const char* __arg0, ... /*,  char* const* __envp */)
    100     __attribute__((__sentinel__(1)));
    101 int fexecve(int __fd, char* const* __argv, char* const* __envp) __INTRODUCED_IN(28);
    102 
    103 int nice(int __incr);
    104 
    105 int setuid(uid_t __uid);
    106 uid_t getuid(void);
    107 int seteuid(uid_t __uid);
    108 uid_t geteuid(void);
    109 int setgid(gid_t __gid);
    110 gid_t getgid(void);
    111 int setegid(gid_t __gid);
    112 gid_t getegid(void);
    113 int getgroups(int __size, gid_t* __list);
    114 int setgroups(size_t __size, const gid_t* __list);
    115 int setreuid(uid_t __ruid, uid_t __euid);
    116 int setregid(gid_t __rgid, gid_t __egid);
    117 int setresuid(uid_t __ruid, uid_t __euid, uid_t __suid);
    118 int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
    119 int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
    120 int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
    121 char* getlogin(void);
    122 int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
    123 
    124 long fpathconf(int __fd, int __name);
    125 long pathconf(const char* __path, int __name);
    126 
    127 int access(const char* __path, int __mode);
    128 int faccessat(int __dirfd, const char* __path, int __mode, int __flags) __INTRODUCED_IN(16);
    129 int link(const char* __old_path, const char* __new_path);
    130 int linkat(int __old_dir_fd, const char* __old_path, int __new_dir_fd, const char* __new_path, int __flags) __INTRODUCED_IN(21);
    131 int unlink(const char* __path);
    132 int unlinkat(int __dirfd, const char* __path, int __flags);
    133 int chdir(const char* __path);
    134 int fchdir(int __fd);
    135 int rmdir(const char* __path);
    136 int pipe(int __fds[2]);
    137 #if defined(__USE_GNU)
    138 int pipe2(int __fds[2], int __flags) __INTRODUCED_IN(9);
    139 #endif
    140 int chroot(const char* __path);
    141 int symlink(const char* __old_path, const char* __new_path);
    142 int symlinkat(const char* __old_path, int __new_dir_fd, const char* __new_path) __INTRODUCED_IN(21);
    143 ssize_t readlink(const char* __path, char* __buf, size_t __buf_size);
    144 ssize_t readlinkat(int __dir_fd, const char* __path, char* __buf, size_t __buf_size)
    145     __INTRODUCED_IN(21);
    146 int chown(const char* __path, uid_t __owner, gid_t __group);
    147 int fchown(int __fd, uid_t __owner, gid_t __group);
    148 int fchownat(int __dir_fd, const char* __path, uid_t __owner, gid_t __group, int __flags);
    149 int lchown(const char* __path, uid_t __owner, gid_t __group);
    150 char* getcwd(char* __buf, size_t __size);
    151 
    152 void sync(void);
    153 #if defined(__USE_GNU)
    154 int syncfs(int __fd) __INTRODUCED_IN(28);
    155 #endif
    156 
    157 int close(int __fd);
    158 
    159 ssize_t read(int __fd, void* __buf, size_t __count);
    160 ssize_t write(int __fd, const void* __buf, size_t __count);
    161 
    162 int dup(int __old_fd);
    163 int dup2(int __old_fd, int __new_fd);
    164 int dup3(int __old_fd, int __new_fd, int __flags) __INTRODUCED_IN(21);
    165 int fsync(int __fd);
    166 int 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)
    170 int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
    171 off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
    172 ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset)
    173   __RENAME(pread64) __INTRODUCED_IN(12);
    174 ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset)
    175   __RENAME(pwrite64) __INTRODUCED_IN(12);
    176 int ftruncate(int __fd, off_t __length) __RENAME(ftruncate64) __INTRODUCED_IN(12);
    177 #else
    178 int truncate(const char* __path, off_t __length);
    179 off_t lseek(int __fd, off_t __offset, int __whence);
    180 ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
    181 ssize_t pwrite(int __fd, const void* __buf, size_t __count, off_t __offset);
    182 int ftruncate(int __fd, off_t __length);
    183 #endif
    184 
    185 int truncate64(const char* __path, off64_t __length) __INTRODUCED_IN(21);
    186 off64_t lseek64(int __fd, off64_t __offset, int __whence);
    187 ssize_t pread64(int __fd, void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12);
    188 ssize_t pwrite64(int __fd, const void* __buf, size_t __count, off64_t __offset) __INTRODUCED_IN(12);
    189 int ftruncate64(int __fd, off64_t __length) __INTRODUCED_IN(12);
    190 
    191 int pause(void);
    192 unsigned int alarm(unsigned int __seconds);
    193 unsigned int sleep(unsigned int __seconds);
    194 int usleep(useconds_t __microseconds);
    195 
    196 int gethostname(char* __buf, size_t __buf_size);
    197 int sethostname(const char* __name, size_t __n) __INTRODUCED_IN(23);
    198 
    199 int brk(void* __addr);
    200 void* sbrk(ptrdiff_t __increment);
    201 
    202 int isatty(int __fd);
    203 char* ttyname(int __fd);
    204 int ttyname_r(int __fd, char* __buf, size_t __buf_size) __INTRODUCED_IN(8);
    205 
    206 int acct(const char* __path);
    207 
    208 #if __ANDROID_API__ >= __ANDROID_API_L__
    209 int getpagesize(void) __INTRODUCED_IN(21);
    210 #else
    211 static __inline__ int getpagesize(void) {
    212   return sysconf(_SC_PAGESIZE);
    213 }
    214 #endif
    215 
    216 long syscall(long __number, ...);
    217 
    218 int daemon(int __no_chdir, int __no_close);
    219 
    220 #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
    221 int cacheflush(long __addr, long __nbytes, long __cache);
    222     /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
    223 #endif
    224 
    225 pid_t tcgetpgrp(int __fd);
    226 int 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 
    236 int getdomainname(char* __buf, size_t __buf_size) __INTRODUCED_IN(26);
    237 int setdomainname(const char* __name, size_t __n) __INTRODUCED_IN(26);
    238 
    239 void 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