diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-04-18 22:00:20 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-04-18 22:00:20 +0000 |
commit | 99a6ee4b85e3be653e2801f61d171763e1fa6015 (patch) | |
tree | 24bb7efbd8b03b2e466c8132ee78c9b7cf886b3e /libc/unistd/execle.c | |
parent | 1f849b3def01f4203e0dee6c5fb9c8eb041ed7b9 (diff) |
Posix 1003.13 POSIX_MULTI_PROCESS specifies that execle() should
be there, so I just wrote it up.
-Erik
Diffstat (limited to 'libc/unistd/execle.c')
-rw-r--r-- | libc/unistd/execle.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libc/unistd/execle.c b/libc/unistd/execle.c new file mode 100644 index 000000000..14c7a0bfc --- /dev/null +++ b/libc/unistd/execle.c @@ -0,0 +1,53 @@ + +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> + +extern int execvep(const char *path, char *const argv[], char *const envp[]); + +int execle(const char *file, const char *arg, ...) +{ + const char *shortargv[16]; + const char **argv; + const char *c; + int i; + va_list args; + const char *const *envp; + + i = 1; + + va_start(args, arg); + + do { + c = va_arg(args, const char *); + + i++; + } while (c); + + va_end(args); + + if (i <= 16) + argv = shortargv; + else { + argv = (const char **) alloca(sizeof(char *) * i); + } + + argv[0] = arg; + i = 1; + + va_start(args, arg); + + do { + argv[i] = va_arg(args, const char *); + } while (argv[i++]); + + envp = va_arg (args, const char *const *); + va_end(args); + + i = execvep(file, (char *const *) argv, (char *const *) envp); + + if (argv != shortargv) + free(argv); + + return i; +} |