2 * Acess2 POSIX Emulation Layer
6 * - POSIX->Acess VFS call translation
11 #include <sys/select.h>
16 int unlink(const char *pathname)
18 return _SysUnlink(pathname);
21 int open(const char *path, int openmode, ...)
23 mode_t create_mode = 0;
26 switch( openmode & O_RDWR )
30 case O_RDONLY: openflags |= OPENFLAG_READ; break;
31 case O_WRONLY: openflags |= OPENFLAG_WRITE; break;
32 case O_RDWR: openflags |= OPENFLAG_READ|OPENFLAG_WRITE; break;
35 if( openmode & O_CREAT ) {
36 openflags |= OPENFLAG_CREATE;
38 va_start(args, openmode);
39 create_mode = va_arg(args, mode_t);
43 if( openmode & O_NONBLOCK )
44 openflags |= OPENFLAG_NONBLOCK;
46 int ret = _SysOpen(path, openflags, create_mode);
47 _SysDebug("open('%s', 0%o, 0%o) = %i", path, openmode, create_mode, ret);
51 int creat(const char *path, mode_t mode)
53 // TODO: Make native call to do this cheaper
54 int fd = _SysOpen(path, OPENFLAG_CREATE, mode);
55 if( fd == -1 ) return -1;
66 ssize_t write(int fd, const void *buf, size_t count)
68 return _SysWrite(fd, buf, count);
71 ssize_t read(int fd, void *buf, size_t count)
73 return _SysRead(fd, buf, count);
76 int seek(int fd, int whence, off_t dest)
78 return _SysSeek(fd, whence, dest);
88 return _SysClone(CLONE_VM, 0);
91 int execv(const char *b, char *v[])
93 return _SysExecVE(b, v, NULL);
98 _SysDebug("libposix: dup() does not share offsets/flags");
99 // NOTE: Acess's CopyFD doesn't cause offset sharing
100 int ret = _SysCopyFD(oldfd, -1);
101 _SysDebug("dup(%i) = %i", oldfd, ret);
105 int dup2(int oldfd, int newfd)
107 _SysDebug("libposix: dup2() does not share offsets/flags");
108 // NOTE: Acess's CopyFD doesn't cause offset sharing
109 _SysDebug("dup2(%i,%i)", oldfd, newfd);
110 return _SysCopyFD(oldfd, newfd);
115 * Set session ID to PID
119 // TODO: actual syscall for this
135 // TODO: Impliment EUIDs in-kernel?
139 int kill(pid_t pid, int signal)
141 // TODO: Need special handling?
142 return _SysKill(pid, signal);
145 int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout)
147 long long int ltimeout = 0, *ltimeoutp = NULL;
150 ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000;
151 ltimeoutp = <imeout;
153 _SysDebug("select(%i,{0x%x},{0x%x},{0x%x},%lli)",
154 nfd, (rfd?rfd->flags[0]:0), (wfd?wfd->flags[0]:0), (efd?efd->flags[0]:0),
155 (ltimeoutp ? *ltimeoutp : -1)
157 return _SysSelect(nfd, rfd, wfd, efd, ltimeoutp, 0);
160 int pipe(int pipefd[2])
162 pipefd[0] = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
163 pipefd[1] = _SysCopyFD(pipefd[0], -1);
164 _SysFDFlags(pipefd[1], OPENFLAG_READ|OPENFLAG_WRITE, OPENFLAG_WRITE);
165 _SysDebug("pipe({%i,%i})", pipefd[0], pipefd[1]);
169 int chdir(const char *dir)
171 return _SysChdir(dir);
174 int mkdir(const char *pathname, mode_t mode)
176 _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode);
180 char *getpass(const char *prompt)
182 static char passbuf[PASS_MAX+1];
183 fprintf(stderr, "%s", prompt);
184 fgets(passbuf, PASS_MAX+1, stdin);
185 fprintf(stderr, "\n");
186 for( int i = strlen(passbuf); i > 0 && (passbuf[i-1] == '\r' || passbuf[i-1] == '\n'); i -- )