1 /* 2 * Copyright 2004-2009, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _UNISTD_H_ 6 #define _UNISTD_H_ 7 8 9 #include <null.h> 10 #include <sys/types.h> 11 12 13 /* access modes */ 14 #define R_OK 4 15 #define W_OK 2 16 #define X_OK 1 17 #define F_OK 0 18 19 /* standard file descriptors */ 20 #define STDIN_FILENO 0 21 #define STDOUT_FILENO 1 22 #define STDERR_FILENO 2 23 24 /* function arguments needed by lockf() */ 25 #define F_ULOCK 0 /* unlock locked sections */ 26 #define F_LOCK 1 /* lock a section for exclusive use */ 27 #define F_TLOCK 2 /* test and lock a section for exclusive use */ 28 #define F_TEST 3 /* test a section for locks by other processes */ 29 30 /* POSIX version support */ 31 #define _POSIX_VERSION (199009L) /* TODO: Update! */ 32 33 #define _POSIX_CHOWN_RESTRICTED 1 34 #define _POSIX_JOB_CONTROL 1 35 #define _POSIX_NO_TRUNC 0 36 #define _POSIX_SAVED_IDS 1 37 #define _POSIX_VDISABLE ((unsigned char)-2) 38 /* TODO: Check this! */ 39 #define _POSIX_SEMAPHORES (200112L) 40 #define _POSIX_THREADS (200112L) 41 42 /* pathconf() constants */ 43 /* BeOS supported values, do not touch */ 44 #define _PC_CHOWN_RESTRICTED 1 45 #define _PC_MAX_CANON 2 46 #define _PC_MAX_INPUT 3 47 #define _PC_NAME_MAX 4 48 #define _PC_NO_TRUNC 5 49 #define _PC_PATH_MAX 6 50 #define _PC_PIPE_BUF 7 51 #define _PC_VDISABLE 8 52 #define _PC_LINK_MAX 25 53 /* new values */ 54 /* TODO: reorder */ 55 #define _PC_SYNC_IO 26 56 #define _PC_ASYNC_IO 27 57 #define _PC_PRIO_IO 28 58 #define _PC_SOCK_MAXBUF 29 59 #define _PC_FILESIZEBITS 30 60 #define _PC_REC_INCR_XFER_SIZE 31 61 #define _PC_REC_MAX_XFER_SIZE 32 62 #define _PC_REC_MIN_XFER_SIZE 33 63 #define _PC_REC_XFER_ALIGN 34 64 #define _PC_ALLOC_SIZE_MIN 35 65 #define _PC_SYMLINK_MAX 36 66 #define _PC_2_SYMLINKS 37 67 #define _PC_XATTR_EXISTS 38 68 #define _PC_XATTR_ENABLED 39 69 70 /* sysconf() constants */ 71 /* BeOS supported values, do not touch */ 72 #define _SC_ARG_MAX 15 73 #define _SC_CHILD_MAX 16 74 #define _SC_CLK_TCK 17 75 #define _SC_JOB_CONTROL 18 76 #define _SC_NGROUPS_MAX 19 77 #define _SC_OPEN_MAX 20 78 #define _SC_SAVED_IDS 21 79 #define _SC_STREAM_MAX 22 80 #define _SC_TZNAME_MAX 23 81 #define _SC_VERSION 24 82 #define _SC_GETGR_R_SIZE_MAX 25 83 #define _SC_GETPW_R_SIZE_MAX 26 84 #define _SC_PAGE_SIZE 27 85 #define _SC_PAGESIZE _SC_PAGE_SIZE 86 #define _SC_SEM_NSEMS_MAX 28 87 #define _SC_SEM_VALUE_MAX 29 88 #define _SC_SEMAPHORES 30 89 #define _SC_THREADS 31 90 /* TODO: check and reorder */ 91 #define _SC_IOV_MAX 32 92 #define _SC_UIO_MAXIOV _SC_IOV_MAX 93 #define _SC_NPROCESSORS_MAX 33 94 #define _SC_NPROCESSORS_CONF 34 95 #define _SC_NPROCESSORS_ONLN 35 96 #define _SC_CPUID_MAX 36 97 #define _SC_ATEXIT_MAX 37 98 #define _SC_PASS_MAX 39 99 #define _SC_PHYS_PAGES 40 100 #define _SC_AVPHYS_PAGES 41 101 #define _SC_PIPE 42 102 #define _SC_SELECT 43 103 #define _SC_POLL 44 104 105 106 /* confstr() constants */ 107 #define _CS_PATH 1 108 109 /* lseek() constants */ 110 #ifndef SEEK_SET 111 # define SEEK_SET 0 112 #endif 113 #ifndef SEEK_CUR 114 # define SEEK_CUR 1 115 #endif 116 #ifndef SEEK_END 117 # define SEEK_END 2 118 #endif 119 120 121 #ifdef __cplusplus 122 extern "C" { 123 #endif 124 125 /* file functions */ 126 extern int access(const char *path, int accessMode); 127 extern int faccessat(int fd, const char *path, int accessMode, int flag); 128 129 extern int chdir(const char *path); 130 extern int fchdir(int fd); 131 extern char *getcwd(char *buffer, size_t size); 132 133 extern int pipe(int fildes[2]); 134 extern int dup(int fd); 135 extern int dup2(int fd1, int fd2); 136 extern int close(int fd); 137 extern int link(const char *toPath, const char *path); 138 extern int linkat(int toFD, const char *toPath, int pathFD, 139 const char *path, int flag); 140 extern int unlink(const char *name); 141 extern int unlinkat(int fd, const char *path, int flag); 142 extern int rmdir(const char *path); 143 144 extern ssize_t readlink(const char *path, char *buffer, size_t bufferSize); 145 extern ssize_t readlinkat(int fd, const char *path, char *buffer, 146 size_t bufferSize); 147 extern int symlink(const char *toPath, const char *symlinkPath); 148 extern int symlinkat(const char *toPath, int fd, const char *symlinkPath); 149 150 extern int ftruncate(int fd, off_t newSize); 151 extern int truncate(const char *path, off_t newSize); 152 extern int ioctl(int fd, unsigned long op, ...); 153 154 extern ssize_t read(int fd, void *buffer, size_t count); 155 extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count); 156 extern ssize_t pread(int fd, void *buffer, size_t count, off_t pos); 157 extern ssize_t write(int fd, const void *buffer, size_t count); 158 extern ssize_t write_pos(int fd, off_t pos, const void *buffer,size_t count); 159 extern ssize_t pwrite(int fd, const void *buffer, size_t count, off_t pos); 160 extern off_t lseek(int fd, off_t offset, int whence); 161 162 extern int sync(void); 163 extern int fsync(int fd); 164 165 extern int chown(const char *path, uid_t owner, gid_t group); 166 extern int fchown(int fd, uid_t owner, gid_t group); 167 extern int lchown(const char *path, uid_t owner, gid_t group); 168 extern int fchownat(int fd, const char *path, uid_t owner, gid_t group, 169 int flag); 170 171 extern int mknod(const char *name, mode_t mode, dev_t dev); 172 extern int mknodat(int fd, const char *name, mode_t mode, dev_t dev); 173 174 extern int getpagesize(void); 175 extern int getdtablesize(void); 176 extern long sysconf(int name); 177 extern long fpathconf(int fd, int name); 178 extern long pathconf(const char *path, int name); 179 extern size_t confstr(int name, char *buf, size_t len); 180 extern int lockf(int fd, int function, off_t size); 181 182 /* process functions */ 183 extern pid_t fork(void); 184 extern pid_t vfork(void); 185 extern int execve(const char *path, char * const argv[], char * const envp[]); 186 extern int execl(const char *path, const char *arg, ...); 187 extern int execv(const char *path, char *const *argv); 188 extern int execlp(const char *file, const char *arg, ...); 189 extern int execle(const char *path, const char *arg , ... /*, char **envp */); 190 extern int exect(const char *path, char *const *argv); 191 extern int execvp(const char *file, char *const *argv); 192 193 extern void _exit(int status); 194 195 extern pid_t tcgetpgrp(int fd); 196 extern int tcsetpgrp(int fd, pid_t pgrpid); 197 extern void *sbrk(long incr); 198 199 extern unsigned int alarm(unsigned int seconds); 200 extern useconds_t ualarm(useconds_t microSeconds, useconds_t interval); 201 extern unsigned int sleep(unsigned int seconds); 202 extern int usleep(unsigned int microSeconds); 203 extern int pause(void); 204 205 /* process */ 206 extern pid_t getpid(void); 207 extern pid_t getpgrp(void); 208 extern pid_t getppid(void); 209 extern pid_t getsid(pid_t pid); 210 extern pid_t getpgid(pid_t pid); 211 212 extern pid_t setsid(void); 213 extern int setpgid(pid_t pid, pid_t pgid); 214 extern pid_t setpgrp(void); 215 216 extern int chroot(const char *path); 217 218 /* access permissions */ 219 extern gid_t getegid(void); 220 extern uid_t geteuid(void); 221 extern gid_t getgid(void); 222 extern uid_t getuid(void); 223 224 extern int setgid(gid_t gid); 225 extern int setuid(uid_t uid); 226 extern int setegid(gid_t gid); 227 extern int seteuid(uid_t uid); 228 extern int setregid(gid_t rgid, gid_t egid); 229 extern int setreuid(uid_t ruid, uid_t euid); 230 231 extern int getgrouplist(const char* user, gid_t baseGroup, 232 gid_t* groupList, int* groupCount); 233 extern int getgroups(int groupCount, gid_t groupList[]); 234 extern int initgroups(const char* user, gid_t baseGroup); 235 extern int setgroups(int groupCount, const gid_t* groupList); 236 237 extern char *getlogin(void); 238 extern int getlogin_r(char *name, size_t nameSize); 239 240 /* host name */ 241 extern int sethostname(const char *hostName, size_t nameSize); 242 extern int gethostname(char *hostName, size_t nameSize); 243 244 /* tty */ 245 extern int isatty(int fd); 246 extern char *ttyname(int fd); 247 extern int ttyname_r(int fd, char *buffer, size_t bufferSize); 248 249 /* misc */ 250 extern char *crypt(const char *key, const char *salt); 251 extern void encrypt(char block[64], int edflag); 252 extern int getopt(int argc, char *const *argv, const char *shortOpts); 253 extern void swab(const void *src, void *dest, ssize_t nbytes); 254 255 /* getopt() related external variables */ 256 extern char *optarg; 257 extern int optind, opterr, optopt; 258 259 #ifdef __cplusplus 260 } 261 #endif 262 263 #endif /* _UNISTD_H_ */ 264