diff options
author | dzwdz | 2023-08-27 02:06:32 +0200 |
---|---|---|
committer | dzwdz | 2023-08-27 02:06:32 +0200 |
commit | e43939bcc6123e02314aa403eef94d5ace441f7f (patch) | |
tree | ac0cea10e8708ae1a6a7a400257c4bc59175a91f /src/libc/unistd.c | |
parent | 1f938c20b4a82ca1267ab9a1ec0922878a21ca6b (diff) |
ports: qbe, cproc :^)
Diffstat (limited to 'src/libc/unistd.c')
-rw-r--r-- | src/libc/unistd.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/libc/unistd.c b/src/libc/unistd.c index 549da89..e87cdb9 100644 --- a/src/libc/unistd.c +++ b/src/libc/unistd.c @@ -77,6 +77,19 @@ int execvp(const char *path, char *const argv[]) { return execve(path, argv, NULL); } +int execvpe(const char *path, char *const argv[], char *const envp[]) { + if (path[0] != '/') { + char *exp = malloc(strlen(path) + 6); + int ret; + strcpy(exp, "/bin/"); + strcat(exp, path); + ret = execve(exp, argv, envp); + free(exp); + return ret; + } + return execve(path, argv, envp); +} + int execve(const char *path, char *const argv[], char *const envp[]) { FILE *file = fopen(path, "e"); char hdr[4] = {0}; @@ -225,8 +238,13 @@ ssize_t write(int fd, const void *buf, size_t count) { } int pipe(int pipefd[2]) { - (void)pipefd; - __libc_panic("unimplemented"); + // TODO pipe buffering + int ret = _sys_pipe(pipefd, 0); + if (ret < 0) { + errno = -ret; + return -1; + } + return 0; } int dup(int oldfd) { @@ -235,8 +253,12 @@ int dup(int oldfd) { } int dup2(int oldfd, int newfd) { - (void)oldfd; (void)newfd; - __libc_panic("unimplemented"); + int ret = _sys_dup(oldfd, newfd, 0); + if (ret < 0) { + errno = -ret; + ret = -1; + } + return ret; } unsigned int sleep(unsigned int seconds) { |