X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibposix.so_src%2Funistd.c;h=dca29630e7e2f5b5e7a60175e681cd77df76e6df;hb=ba78deafcc3016555469ed263d7a0370fa99db4b;hp=e41ebfd0894f1f4778c9daa7c0581df7634c513f;hpb=8052e522542c004cb8fe6970d3313184a27763c2;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index e41ebfd0..dca29630 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -12,6 +12,7 @@ #include #include #include +#include // === CODE === int unlink(const char *pathname) @@ -49,6 +50,12 @@ int open(const char *path, int openmode, ...) return ret; } +int access(const char *path, int openmode) +{ + errno = EINVAL; + return -1; +} + int creat(const char *path, mode_t mode) { // TODO: Make native call to do this cheaper @@ -116,6 +123,18 @@ int dup2(int oldfd, int newfd) return _SysCopyFD(oldfd, newfd); } +int chown(const char *path, uid_t owner, gid_t group) +{ + _SysDebug("TODO: chown(%s, %i, %i)", path, owner, group); + errno = ENOTIMPL; + return -1; +} +int chmod(const char *path, mode_t mode) +{ + _SysDebug("TODO: chmod(%s, 0%o)", path, mode); + errno = ENOTIMPL; + return -1; +} /* * Set session ID to PID @@ -135,6 +154,10 @@ uid_t getuid(void) { return _SysGetUID(); } +gid_t getgid(void) +{ + return _SysGetGID(); +} uid_t geteuid(void) { @@ -142,6 +165,41 @@ uid_t geteuid(void) return _SysGetUID(); } +int seteuid(uid_t euid) +{ + _SysDebug("TODO: %s", __func__); + return 0; +} +int setegid(gid_t egid) +{ + _SysDebug("TODO: %s", __func__); + return 0; +} + +unsigned int sleep(unsigned int seconds) +{ + int64_t start = _SysTimestamp(); + _SysTimedSleep( seconds*1000 ); + return (_SysTimestamp() - start) / 1000; +} + +int usleep(useconds_t usec) +{ + _SysTimedSleep( (usec+999)/1000 ); + return 0; +} + +unsigned int alarm(unsigned int seconds) +{ + static int64_t alarm_time; + if( seconds > 0 ) + { + alarm_time = _SysTimestamp() + seconds * 1000; + // TODO: Schedule SIGALRM + } + return (alarm_time - _SysTimestamp()) / 1000; +} + int kill(pid_t pid, int signal) { // TODO: Need special handling? @@ -150,7 +208,7 @@ 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; + int64_t ltimeout = 0, *ltimeoutp = NULL; if( timeout ) { ltimeout = timeout->tv_sec*1000 + timeout->tv_usec / 1000; @@ -177,12 +235,21 @@ int chdir(const char *dir) return _SysChdir(dir); } -int mkdir(const char *pathname, mode_t mode) +int rmdir(const char *pathname) { - _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode); +// return _SysUnlink(pathname); + _SysDebug("TODO: POSIX rmdir('%s')", pathname); + errno = ENOTIMPL; return -1; } +int mkdir(const char *pathname, mode_t mode) +{ + _SysDebug("TODO: POSIX mkdir('%s', 0%o)", pathname, mode); + _SysMkDir(pathname); + return 0; +} + char *getpass(const char *prompt) { static char passbuf[PASS_MAX+1]; @@ -192,6 +259,7 @@ char *getpass(const char *prompt) mode.OutputMode = 0; _SysIOCtl(STDIN_FILENO, PTY_IOCTL_SETMODE, &mode); fprintf(stderr, "%s", prompt); + fflush(stdin); // clear stdin buffer 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 -- ) @@ -202,3 +270,43 @@ char *getpass(const char *prompt) return passbuf; } +char *ttyname(int fd) +{ + static char ttyname_buf[32]; + errno = ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf)); + if(errno) return NULL; + + return ttyname_buf; +} +int ttyname_r(int fd, char *buf, size_t buflen) +{ + int type = _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL); + if( type == -1 ) + return errno; + if( type != DRV_TYPE_TERMINAL ) + return ENOTTY; + + _SysIOCtl(fd, PTY_IOCTL_GETID, NULL); + + _SysDebug("TODO: ttyname_r"); + + return ENOTIMPL; +} + +int isatty(int fd) +{ + if( fd < 0 ) { + errno = EBADF; + return 0; + } + + int type = _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL); + if( type == -1 ) + return 0; + if( type != DRV_TYPE_TERMINAL ) { + errno = ENOTTY; + // NOTE: Pre POSIX 2001, EINVAL was returned + return 0; + } + return 1; +}