2 * Acess2 POSIX Emulation Layer
6 * - POSIX->Acess VFS call translation
11 #include <sys/select.h>
15 int unlink(const char *pathname)
17 return _SysUnlink(pathname);
20 int open(const char *path, int openmode, ...)
22 mode_t create_mode = 0;
25 switch( openmode & O_RDWR )
29 case O_RDONLY: openflags |= OPENFLAG_READ; break;
30 case O_WRONLY: openflags |= OPENFLAG_WRITE; break;
31 case O_RDWR: openflags |= OPENFLAG_READ|OPENFLAG_WRITE; break;
34 if( openmode & O_CREAT ) {
35 openflags |= OPENFLAG_CREATE;
37 va_start(args, openmode);
38 create_mode = va_arg(args, mode_t);
42 return _SysOpen(path, openflags, create_mode);
45 int creat(const char *path, mode_t mode)
47 // TODO: Make native call to do this cheaper
48 int fd = _SysOpen(path, OPENFLAG_CREATE, mode);
49 if( fd == -1 ) return -1;
60 ssize_t write(int fd, const void *buf, size_t count)
62 return _SysWrite(fd, buf, count);
65 ssize_t read(int fd, void *buf, size_t count)
67 return _SysRead(fd, buf, count);
70 int seek(int fd, int whence, off_t dest)
72 return _SysSeek(fd, whence, dest);
82 return _SysClone(CLONE_VM, 0);
85 int execv(const char *b, char *v[])
87 return _SysExecVE(b, v, NULL);
92 _SysDebug("libposix: dup() does not share offsets/flags");
93 // NOTE: Acess's CopyFD doesn't cause offset sharing
94 // TODO: Check that -1 does cause a new allocation
95 return _SysCopyFD(oldfd, -1);
98 int dup2(int oldfd, int newfd)
100 _SysDebug("libposix: dup2() does not share offsets/flags");
101 // NOTE: Acess's CopyFD doesn't cause offset sharing
102 return _SysCopyFD(oldfd, newfd);
107 * Set session ID to PID
111 // TODO: actual syscall for this
127 // TODO: Impliment EUIDs in-kernel?
131 int kill(pid_t pid, int signal)
133 // TODO: Need special handling?
134 return _SysKill(pid, signal);
137 int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout)
142 long long int ltimeout = 0;
143 ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000;
144 int ret = _SysSelect(nfd, rfd, wfd, efd, <imeout, 0);
149 return _SysSelect(nfd, rfd, wfd, efd, NULL, 0);
153 int pipe(int pipefd[2])
155 pipefd[0] = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
156 pipefd[1] = _SysCopyFD(pipefd[0], -1);
157 _SysFDFlags(pipefd[1], OPENFLAG_READ|OPENFLAG_WRITE, OPENFLAG_WRITE);
161 int chdir(const char *dir)
163 return _SysChdir(dir);
166 int mkdir(const char *pathname, mode_t mode)
168 _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode);
172 char *getpass(const char *prompt)
174 static char passbuf[PASS_MAX+1];
175 fprintf(stderr, "%s", prompt);
176 fgets(passbuf, PASS_MAX+1, stdin);
177 fprintf(stderr, "\n");