1 /* 2 * Copyright 2004-2007, 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) 32 33 /* pathconf() constants */ 34 #define _PC_CHOWN_RESTRICTED 1 35 #define _PC_MAX_CANON 2 36 #define _PC_MAX_INPUT 3 37 #define _PC_NAME_MAX 4 38 #define _PC_NO_TRUNC 5 39 #define _PC_PATH_MAX 6 40 #define _PC_PIPE_BUF 7 41 #define _PC_VDISABLE 8 42 #define _PC_LINK_MAX 25 43 #define _POSIX_CHOWN_RESTRICTED 9 44 #define _POSIX_JOB_CONTROL 10 45 #define _POSIX_NO_TRUNC 11 46 #define _POSIX_SAVED_IDS 12 47 #define _POSIX_VDISABLE ((cc_t) - 2) 48 49 /* sysconf() constants */ 50 #define _SC_ARG_MAX 15 51 #define _SC_CHILD_MAX 16 52 #define _SC_CLK_TCK 17 53 #define _SC_JOB_CONTROL 18 54 #define _SC_NGROUPS_MAX 19 55 #define _SC_OPEN_MAX 20 56 #define _SC_SAVED_IDS 21 57 #define _SC_STREAM_MAX 22 58 #define _SC_TZNAME_MAX 23 59 #define _SC_VERSION 24 60 61 /* lseek() constants */ 62 #ifndef SEEK_SET 63 # define SEEK_SET 0 64 #endif 65 #ifndef SEEK_CUR 66 # define SEEK_CUR 1 67 #endif 68 #ifndef SEEK_END 69 # define SEEK_END 2 70 #endif 71 72 73 #ifdef __cplusplus 74 extern "C" { 75 #endif 76 77 /* file functions */ 78 extern int access(const char *path, int accessMode); 79 80 extern int chdir(const char *path); 81 extern int fchdir(int fd); 82 extern char *getcwd(char *buffer, size_t size); 83 84 extern int pipe(int fildes[2]); 85 extern int dup(int fd); 86 extern int dup2(int fd1, int fd2); 87 extern int close(int fd); 88 extern int link(const char *name, const char *new_name); 89 extern int unlink(const char *name); 90 extern int rmdir(const char *path); 91 92 extern ssize_t readlink(const char *path, char *buffer, size_t bufferSize); 93 extern int symlink(const char *from, const char *to); 94 95 extern int ftruncate(int fd, off_t newSize); 96 extern int truncate(const char *path, off_t newSize); 97 extern int ioctl(int fd, unsigned long op, ...); 98 99 extern ssize_t read(int fd, void *buffer, size_t count); 100 extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count); 101 extern ssize_t pread(int fd, void *buffer, size_t count, off_t pos); 102 extern ssize_t write(int fd, const void *buffer, size_t count); 103 extern ssize_t write_pos(int fd, off_t pos, const void *buffer,size_t count); 104 extern ssize_t pwrite(int fd, const void *buffer, size_t count, off_t pos); 105 extern off_t lseek(int fd, off_t offset, int whence); 106 107 extern int sync(void); 108 extern int fsync(int fd); 109 110 extern int chown(const char *path, uid_t owner, gid_t group); 111 extern int fchown(int fd, uid_t owner, gid_t group); 112 extern int lchown(const char *path, uid_t owner, gid_t group); 113 114 extern int mknod(const char *name, mode_t mode, dev_t dev); 115 116 extern int getdtablesize(void); 117 extern long sysconf(int name); 118 extern long fpathconf(int fd, int name); 119 extern long pathconf(const char *path, int name); 120 extern size_t confstr(int name, char *buf, size_t len); 121 extern int lockf(int fd, int function, off_t size); 122 123 /* process functions */ 124 extern pid_t fork(void); 125 extern pid_t vfork(void); 126 extern int execve(const char *path, char * const argv[], char * const envp[]); 127 extern int execl(const char *path, const char *arg, ...); 128 extern int execv(const char *path, char *const *argv); 129 extern int execlp(const char *file, const char *arg, ...); 130 extern int execle(const char *path, const char *arg , ... /*, char **envp */); 131 extern int exect(const char *path, char *const *argv); 132 extern int execvp(const char *file, char *const *argv); 133 134 extern void _exit(int status); 135 136 extern pid_t tcgetpgrp(int fd); 137 extern int tcsetpgrp(int fd, pid_t pgrpid); 138 extern void *sbrk(long incr); 139 140 extern unsigned int alarm(unsigned int seconds); 141 extern useconds_t ualarm(useconds_t microSeconds, useconds_t interval); 142 extern unsigned int sleep(unsigned int seconds); 143 extern int usleep(unsigned int microSeconds); 144 extern clock_t clock(void); 145 extern int pause(void); 146 147 /* process */ 148 extern pid_t getpid(void); 149 extern pid_t getpgrp(void); 150 extern pid_t getppid(void); 151 extern pid_t getsid(pid_t pid); 152 extern pid_t getpgid(pid_t pid); 153 154 extern pid_t setsid(void); 155 extern int setpgid(pid_t pid, pid_t pgid); 156 extern pid_t setpgrp(void); 157 158 /* access permissions */ 159 extern gid_t getegid(void); 160 extern uid_t geteuid(void); 161 extern gid_t getgid(void); 162 extern uid_t getuid(void); 163 extern int getgroups(int groupSize, gid_t groupList[]); 164 165 extern int setgid(gid_t gid); 166 extern int setuid(uid_t uid); 167 extern int setegid(gid_t gid); 168 extern int seteuid(uid_t uid); 169 extern int setregid(gid_t rgid, gid_t egid); 170 extern int setreuid(uid_t ruid, uid_t euid); 171 172 extern char *getlogin(void); 173 extern int getlogin_r(char *name, size_t nameSize); 174 175 /* host name */ 176 extern int sethostname(const char *hostName, size_t nameSize); 177 extern int gethostname(char *hostName, size_t nameSize); 178 179 /* tty */ 180 extern int isatty(int fd); 181 extern char *ttyname(int fd); 182 extern int ttyname_r(int fd, char *buffer, size_t bufferSize); 183 184 /* misc */ 185 extern char *crypt(const char *key, const char *salt); 186 extern void encrypt(char block[64], int edflag); 187 extern int getopt(int argc, char *const *argv, const char *shortOpts); 188 extern void swab(const void *src, void *dest, ssize_t nbytes); 189 190 /* getopt() related external variables */ 191 extern char *optarg; 192 extern int optind, opterr, optopt; 193 194 // ToDo: should be moved to stdlib.h 195 extern char **environ; 196 197 #ifdef __cplusplus 198 } 199 #endif 200 201 #endif /* _UNISTD_H_ */ 202