Annotation of /trunk/multiarch-wrapper/multiarch-wrapper.c
Parent Directory | Revision Log
Revision 1150 -
(hide annotations)
(download)
Fri Aug 20 16:59:22 2010 UTC (14 years, 1 month ago) by niro
File MIME type: text/plain
File size: 841 byte(s)
Fri Aug 20 16:59:22 2010 UTC (14 years, 1 month ago) by niro
File MIME type: text/plain
File size: 841 byte(s)
-fixed wrapper to match our buildsystem (multilib.sminc)
1 | niro | 1148 | #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 | niro | 1150 | # define DEF_SUFFIX "m64" |
12 | niro | 1148 | #endif |
13 | |||
14 | int main(int argc, char **argv) | ||
15 | { | ||
16 | char *filename; | ||
17 | char *suffix; | ||
18 | |||
19 | niro | 1150 | if(!(suffix = getenv("ABI"))) |
20 | suffix = DEF_SUFFIX; | ||
21 | niro | 1148 | |
22 | if (asprintf(&filename, "%s-%s", argv[0], suffix) < 0) { | ||
23 | perror(argv[0]); | ||
24 | return -1; | ||
25 | } | ||
26 | |||
27 | int status = EXIT_FAILURE; | ||
28 | pid_t pid = fork(); | ||
29 | |||
30 | if (pid == 0) { | ||
31 | execvp(filename, argv); | ||
32 | perror(filename); | ||
33 | goto end; | ||
34 | } else if (pid < 0) { | ||
35 | goto end_error; | ||
36 | } else { | ||
37 | if (waitpid(pid, &status, 0) != pid) { | ||
38 | status = EXIT_FAILURE; | ||
39 | goto end_error; | ||
40 | } | ||
41 | status = WEXITSTATUS(status); | ||
42 | } | ||
43 | goto end; | ||
44 | |||
45 | end_error: | ||
46 | perror(argv[0]); | ||
47 | end: | ||
48 | free(filename); | ||
49 | |||
50 | return status; | ||
51 | } | ||
52 | |||
53 |