Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | #include <stdarg.h> |
| 3 | |
Rich Felker | e6bac87 | 2011-04-27 16:06:33 -0400 | [diff] [blame] | 4 | int execlp(const char *file, const char *argv0, ...) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 5 | { |
| 6 | int argc; |
| 7 | va_list ap; |
Rich Felker | e6bac87 | 2011-04-27 16:06:33 -0400 | [diff] [blame] | 8 | va_start(ap, argv0); |
| 9 | for (argc=1; va_arg(ap, const char *); argc++); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 10 | va_end(ap); |
| 11 | { |
| 12 | int i; |
| 13 | char *argv[argc+1]; |
Rich Felker | e6bac87 | 2011-04-27 16:06:33 -0400 | [diff] [blame] | 14 | va_start(ap, argv0); |
| 15 | argv[0] = (char *)argv0; |
| 16 | for (i=1; i<argc; i++) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 17 | argv[i] = va_arg(ap, char *); |
| 18 | argv[i] = NULL; |
Szabolcs Nagy | c3a43b3 | 2013-10-07 13:24:00 +0000 | [diff] [blame] | 19 | va_end(ap); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 20 | return execvp(file, argv); |
| 21 | } |
| 22 | } |