From 47ee52dc0ad5adffb8da68355132acf5d2051cce Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 30 Mar 2023 21:28:39 +0200 Subject: [PATCH] libc: Add execl() --- libc/include/unistd.h | 3 +++ libc/src/unistd.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libc/include/unistd.h b/libc/include/unistd.h index b0403e6e..8944b8bb 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -31,6 +31,9 @@ extern "C" /* Replace the current process with another one. On success, does not return. */ int execv(const char* path, char* const* argv); + /* Replace the current process with another one. On success, does not return. */ + int execl(const char* path, const char* arg, ...); + int execve(const char*, char* const*, char* const*); int execvp(const char*, char* const*); diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 58a219cd..f4bc4ee4 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -31,6 +33,26 @@ extern "C" __errno_return(rc, int); } + int execl(const char* path, const char* arg, ...) + { + va_list ap; + va_start(ap, arg); + + Vector args; + if (args.try_append(const_cast(arg)).has_error()) return -1; + + while (true) + { + char* str = va_arg(ap, char*); + if (args.try_append(str).has_error()) return -1; + if (!str) break; + } + + va_end(ap); + + return execv(path, args.data()); + } + long syscall(long num, ...) { va_list ap;