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