libc: Add execl()
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
apio 2023-03-30 21:28:39 +02:00
parent 64bca780a7
commit 47ee52dc0a
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 25 additions and 0 deletions

View File

@ -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*);

View File

@ -1,3 +1,5 @@
#include <luna/Vector.h>
#include <bits/errno-return.h>
#include <fcntl.h>
#include <stdarg.h>
@ -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<char*> args;
if (args.try_append(const_cast<char*>(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;