Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/exec_l.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1011 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1011 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
2 | * exec_l.c |
3 | * |
4 | * Common implementation of execl() execle() execlp() |
5 | */ |
6 | |
7 | #include <stdarg.h> |
8 | #include <alloca.h> |
9 | #include <unistd.h> |
10 | |
11 | int NAME(const char *path, const char *arg0, ...) |
12 | { |
13 | va_list ap, cap; |
14 | int argc = 1, rv; |
15 | const char **argv, **argp; |
16 | const char *arg; |
17 | char *const *envp; |
18 | |
19 | va_start(ap, arg0); |
20 | va_copy(cap, ap); |
21 | |
22 | /* Count the number of arguments */ |
23 | do { |
24 | arg = va_arg(cap, const char *); |
25 | argc++; |
26 | } while (arg); |
27 | |
28 | va_end(cap); |
29 | |
30 | /* Allocate memory for the pointer array */ |
31 | argp = argv = alloca(argc * sizeof(const char *)); |
32 | if (!argv) { |
33 | va_end(ap); |
34 | return -1; |
35 | } |
36 | |
37 | /* Copy the list into an array */ |
38 | *argp++ = arg0; |
39 | do { |
40 | *argp++ = arg = va_arg(ap, const char *); |
41 | } while (arg); |
42 | |
43 | #if EXEC_E |
44 | /* execle() takes one more argument for the environment pointer */ |
45 | envp = va_arg(ap, char *const *); |
46 | #else |
47 | envp = environ; |
48 | #endif |
49 | |
50 | #if EXEC_P |
51 | rv = execvpe(path, (char * const *)argv, envp); |
52 | #else |
53 | rv = execve(path, (char * const *)argv, envp); |
54 | #endif |
55 | |
56 | va_end(ap); |
57 | |
58 | return rv; |
59 | } |