libc: Add execv()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-18 22:31:16 +01:00
parent a4ac3c85ed
commit e664af4c2b
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 10 additions and 2 deletions

View File

@ -38,5 +38,5 @@ int main()
fprintf(stderr, "init is running as PID %d\n", getpid()); fprintf(stderr, "init is running as PID %d\n", getpid());
char* argv[] = { "/bin/hello", "--help", NULL }; char* argv[] = { "/bin/hello", "--help", NULL };
syscall(SYS_exec, "/bin/hello", argv); execv("/bin/hello", argv);
} }

View File

@ -23,7 +23,9 @@ extern "C"
/* Return the current process' process ID. */ /* Return the current process' process ID. */
pid_t getpid(void); pid_t getpid(void);
int execv(const char*, char* const*); /* Replace the current process with another one. On success, does not return. */
int execv(const char* path, char* const* argv);
int execve(const char*, char* const*, char* const*); int execve(const char*, char* const*, char* const*);
int execvp(const char*, char* const*); int execvp(const char*, char* const*);

View File

@ -13,6 +13,12 @@ extern "C"
return (pid_t)syscall(SYS_getpid); return (pid_t)syscall(SYS_getpid);
} }
int execv(const char* path, char* const* argv)
{
long rc = syscall(SYS_exec, path, argv);
__errno_return(rc, int);
}
long syscall(long num, ...) long syscall(long num, ...)
{ {
va_list ap; va_list ap;