diff --git a/include/bits/unistd.h b/include/bits/unistd.h index da27ac6fd36250ca5c93a879ff03207f257f2b20..17cf6fa25f1c445eef96a9bd773b32bf9a64dcf1 100644 --- a/include/bits/unistd.h +++ b/include/bits/unistd.h @@ -9,6 +9,7 @@ extern "C" { int execl(const char *path, const char* argv0, ...); int execle(const char *path, const char* argv0, ...); +int execlp(const char *file, const char* argv0, ...); #ifdef __cplusplus } // extern "C" diff --git a/src/c/unistd.c b/src/c/unistd.c index 6247f9333fc488396ef613ed7b9b3604b679ee00..971cab32b3e9cb69513bd7919dff2001b0b0698d 100644 --- a/src/c/unistd.c +++ b/src/c/unistd.c @@ -47,3 +47,26 @@ int execle(const char *path, const char* argv0, ...) return execve(path, argv, envp); } } + +int execvp(const char *file, char *const *argv); + +int execlp(const char *file, const char* argv0, ...) +{ + int argc; + va_list ap; + va_start(ap, argv0); + for (argc = 1; va_arg(ap, const char*); argc++); + va_end(ap); + { + int i; + char *argv[argc+1]; + va_start(ap, argv0); + argv[0] = (char *)argv0; + for (i = 1; i < argc; i++) { + argv[i] = va_arg(ap, char *); + } + argv[i] = NULL; + va_end(ap); + return execvp(file, argv); + } +}