X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibposix.so_src%2Funistd.c;h=e41ebfd0894f1f4778c9daa7c0581df7634c513f;hb=ad12abcd42d1c8f0bd196c6c824a054545cf66d2;hp=9234319ee1adaf3694cf17517c97bfd72ac2c71f;hpb=e91f60e14b8857312238d729fa580d6ab44ba27a;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 9234319e..e41ebfd0 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include // === CODE === int unlink(const char *pathname) @@ -38,7 +41,12 @@ int open(const char *path, int openmode, ...) va_end(args); } - return _SysOpen(path, openflags, create_mode); + if( openmode & O_NONBLOCK ) + openflags |= OPENFLAG_NONBLOCK; + + int ret = _SysOpen(path, openflags, create_mode); + _SysDebug("open('%s', 0%o, 0%o) = %i", path, openmode, create_mode, ret); + return ret; } int creat(const char *path, mode_t mode) @@ -71,6 +79,11 @@ int seek(int fd, int whence, off_t dest) return _SysSeek(fd, whence, dest); } +off_t lseek(int fd, off_t offset, int whence) +{ + return _SysSeek(fd, whence, offset); +} + off_t tell(int fd) { return _SysTell(fd); @@ -88,17 +101,31 @@ int execv(const char *b, char *v[]) int dup(int oldfd) { + _SysDebug("libposix: dup() does not share offsets/flags"); // NOTE: Acess's CopyFD doesn't cause offset sharing - // TODO: Check that -1 does cause a new allocation - return _SysCopyFD(oldfd, -1); + int ret = _SysCopyFD(oldfd, -1); + _SysDebug("dup(%i) = %i", oldfd, ret); + return ret; } int dup2(int oldfd, int newfd) { + _SysDebug("libposix: dup2() does not share offsets/flags"); // NOTE: Acess's CopyFD doesn't cause offset sharing + _SysDebug("dup2(%i,%i)", oldfd, newfd); return _SysCopyFD(oldfd, newfd); } + +/* + * Set session ID to PID + */ +pid_t setsid(void) +{ + // TODO: actual syscall for this + return _SysGetPID(); +} + pid_t getpid(void) { return _SysGetPID(); @@ -109,6 +136,12 @@ uid_t getuid(void) return _SysGetUID(); } +uid_t geteuid(void) +{ + // TODO: Impliment EUIDs in-kernel? + return _SysGetUID(); +} + int kill(pid_t pid, int signal) { // TODO: Need special handling? @@ -117,18 +150,17 @@ int kill(pid_t pid, int signal) int select(int nfd, fd_set *rfd, fd_set *wfd, fd_set *efd, struct timeval *timeout) { - + long long int ltimeout = 0, *ltimeoutp = NULL; if( timeout ) { - long long int ltimeout = 0; ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000; - int ret = _SysSelect(nfd, rfd, wfd, efd, <imeout, 0); - return ret; - } - else - { - return _SysSelect(nfd, rfd, wfd, efd, NULL, 0); + ltimeoutp = <imeout; } + _SysDebug("select(%i,{0x%x},{0x%x},{0x%x},%lli)", + nfd, (rfd?rfd->flags[0]:0), (wfd?wfd->flags[0]:0), (efd?efd->flags[0]:0), + (ltimeoutp ? *ltimeoutp : -1) + ); + return _SysSelect(nfd, rfd, wfd, efd, ltimeoutp, 0); } int pipe(int pipefd[2]) @@ -136,6 +168,37 @@ int pipe(int pipefd[2]) pipefd[0] = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); pipefd[1] = _SysCopyFD(pipefd[0], -1); _SysFDFlags(pipefd[1], OPENFLAG_READ|OPENFLAG_WRITE, OPENFLAG_WRITE); + _SysDebug("pipe({%i,%i})", pipefd[0], pipefd[1]); return 0; } +int chdir(const char *dir) +{ + return _SysChdir(dir); +} + +int mkdir(const char *pathname, mode_t mode) +{ + _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode); + return -1; +} + +char *getpass(const char *prompt) +{ + static char passbuf[PASS_MAX+1]; + struct ptymode oldmode, mode; + _SysIOCtl(STDIN_FILENO, PTY_IOCTL_GETMODE, &oldmode); + mode.InputMode = PTYIMODE_CANON; + mode.OutputMode = 0; + _SysIOCtl(STDIN_FILENO, PTY_IOCTL_SETMODE, &mode); + fprintf(stderr, "%s", prompt); + fgets(passbuf, PASS_MAX+1, stdin); + fprintf(stderr, "\n"); + for( int i = strlen(passbuf); i > 0 && (passbuf[i-1] == '\r' || passbuf[i-1] == '\n'); i -- ) + passbuf[i-1] = 0; + + _SysIOCtl(STDIN_FILENO, PTY_IOCTL_SETMODE, &oldmode); + + return passbuf; +} +