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