Annotation of /trunk/multiarch-wrapper/multiarch-wrapper.c
Parent Directory | Revision Log
Revision 1111 -
(hide annotations)
(download)
Fri Aug 20 15:45:41 2010 UTC (14 years, 1 month ago) by niro
File MIME type: text/plain
File size: 886 byte(s)
Fri Aug 20 15:45:41 2010 UTC (14 years, 1 month ago) by niro
File MIME type: text/plain
File size: 886 byte(s)
added multiarch wrapper
1 | niro | 1111 | #define _GNU_SOURCE |
2 | |||
3 | #include <errno.h> | ||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <sys/types.h> | ||
7 | #include <sys/wait.h> | ||
8 | #include <unistd.h> | ||
9 | |||
10 | #ifndef DEF_SUFFIX | ||
11 | # define DEF_SUFFIX "64" | ||
12 | #endif | ||
13 | |||
14 | int main(int argc, char **argv) | ||
15 | { | ||
16 | char *filename; | ||
17 | char *suffix; | ||
18 | |||
19 | if(!(suffix = getenv("USE_ARCH"))) | ||
20 | if(!(suffix = getenv("BUILDENV"))) | ||
21 | suffix = DEF_SUFFIX; | ||
22 | |||
23 | if (asprintf(&filename, "%s-%s", argv[0], suffix) < 0) { | ||
24 | perror(argv[0]); | ||
25 | return -1; | ||
26 | } | ||
27 | |||
28 | int status = EXIT_FAILURE; | ||
29 | pid_t pid = fork(); | ||
30 | |||
31 | if (pid == 0) { | ||
32 | execvp(filename, argv); | ||
33 | perror(filename); | ||
34 | goto end; | ||
35 | } else if (pid < 0) { | ||
36 | goto end_error; | ||
37 | } else { | ||
38 | if (waitpid(pid, &status, 0) != pid) { | ||
39 | status = EXIT_FAILURE; | ||
40 | goto end_error; | ||
41 | } | ||
42 | status = WEXITSTATUS(status); | ||
43 | } | ||
44 | goto end; | ||
45 | |||
46 | end_error: | ||
47 | perror(argv[0]); | ||
48 | end: | ||
49 | free(filename); | ||
50 | |||
51 | return status; | ||
52 | } | ||
53 | |||
54 |