diff options
author | Simon Tatham <anakin@pobox.com> | 2017-05-18 07:09:40 +0100 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2017-05-18 07:10:17 +0100 |
commit | 3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f (patch) | |
tree | 5d8299dec3ce144bb5765382b6268fb39a856542 | |
parent | 48919caa7b9fb99ba8196098c0ca2e1b3dae5160 (diff) | |
download | wix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.tar.gz wix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.tar.bz2 wix-on-linux-3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f.zip |
Move system_argv_* into their own file.
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | dupstr.h | 2 | ||||
-rw-r--r-- | fake-lib.c | 52 | ||||
-rw-r--r-- | fake-lib.h | 2 | ||||
-rw-r--r-- | fake-msi.c | 1 | ||||
-rw-r--r-- | fake-winterop.c | 1 | ||||
-rw-r--r-- | subproc.c | 59 | ||||
-rw-r--r-- | subproc.h | 6 |
8 files changed, 72 insertions, 57 deletions
diff --git a/Makefile.am b/Makefile.am index b0141dc..806366a 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -5,10 +5,10 @@ ACLOCAL_AMFLAGS = -I m4 | |||
5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la | 5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la |
6 | 6 | ||
7 | libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ | 7 | libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ |
8 | memory.c memory.h dupstr.c dupstr.h | 8 | memory.c memory.h dupstr.c dupstr.h subproc.c subproc.h |
9 | 9 | ||
10 | libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ | 10 | libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ |
11 | memory.c memory.h version.c dupstr.c dupstr.h | 11 | memory.c memory.h version.c dupstr.c dupstr.h subproc.c subproc.h |
12 | 12 | ||
13 | libpreload_la_SOURCES = preload.c | 13 | libpreload_la_SOURCES = preload.c |
14 | libpreload_la_LDFLAGS = -ldl | 14 | libpreload_la_LDFLAGS = -ldl |
@@ -1,6 +1,8 @@ | |||
1 | #include <stddef.h> | 1 | #include <stddef.h> |
2 | 2 | ||
3 | #ifndef cNULL | ||
3 | #define cNULL ((const char *)NULL) | 4 | #define cNULL ((const char *)NULL) |
5 | #endif | ||
4 | 6 | ||
5 | char *dupstr(const char *str); | 7 | char *dupstr(const char *str); |
6 | char *dupcat(const char *str, ...); | 8 | char *dupcat(const char *str, ...); |
@@ -7,10 +7,6 @@ | |||
7 | #include <uchar.h> | 7 | #include <uchar.h> |
8 | #include <err.h> | 8 | #include <err.h> |
9 | 9 | ||
10 | #include <sys/types.h> | ||
11 | #include <sys/wait.h> | ||
12 | #include <unistd.h> | ||
13 | |||
14 | #include "memory.h" | 10 | #include "memory.h" |
15 | #include "fake-lib.h" | 11 | #include "fake-lib.h" |
16 | 12 | ||
@@ -29,54 +25,6 @@ char *ascii(const char16_t *wstr, bool translate_slashes) | |||
29 | return ret; | 25 | return ret; |
30 | } | 26 | } |
31 | 27 | ||
32 | void system_argv_array(char **args) | ||
33 | { | ||
34 | pid_t pid = fork(); | ||
35 | if (pid < 0) | ||
36 | err(1, "fork"); | ||
37 | |||
38 | if (pid == 0) { | ||
39 | execvp(args[0], args); | ||
40 | warn("execvp"); | ||
41 | _exit(127); | ||
42 | } | ||
43 | |||
44 | int status; | ||
45 | if (waitpid(pid, &status, 0) != pid) | ||
46 | err(1, "waitpid"); | ||
47 | if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) | ||
48 | errx(1, "subcommand failed"); | ||
49 | } | ||
50 | |||
51 | void system_argv(const char *cmd, ...) | ||
52 | { | ||
53 | int nargs, nchars; | ||
54 | const char *word; | ||
55 | va_list ap; | ||
56 | |||
57 | va_start(ap, cmd); | ||
58 | nargs = 1; /* terminating NULL */ | ||
59 | nchars = 0; | ||
60 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
61 | nargs++; | ||
62 | nchars += 1 + strlen(word); | ||
63 | } | ||
64 | va_end(ap); | ||
65 | |||
66 | char *args[nargs], chars[nchars]; | ||
67 | char **argp = args, *charp = chars; | ||
68 | va_start(ap, cmd); | ||
69 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
70 | *argp++ = charp; | ||
71 | strcpy(charp, word); | ||
72 | charp += 1 + strlen(word); | ||
73 | } | ||
74 | va_end(ap); | ||
75 | *argp++ = NULL; | ||
76 | |||
77 | system_argv_array(args); | ||
78 | } | ||
79 | |||
80 | void c16cpy(char16_t *out, uint32_t *outsize, char *s) | 28 | void c16cpy(char16_t *out, uint32_t *outsize, char *s) |
81 | { | 29 | { |
82 | uint32_t retlen = 0; | 30 | uint32_t retlen = 0; |
@@ -2,6 +2,4 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | char *ascii(const char16_t *wstr, bool translate_slashes); | 4 | char *ascii(const char16_t *wstr, bool translate_slashes); |
5 | void system_argv(const char *cmd, ...); | ||
6 | void system_argv_array(char **args); | ||
7 | void c16cpy(char16_t *out, uint32_t *outsize, char *s); | 5 | void c16cpy(char16_t *out, uint32_t *outsize, char *s); |
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include "memory.h" | 17 | #include "memory.h" |
18 | #include "dupstr.h" | 18 | #include "dupstr.h" |
19 | #include "subproc.h" | ||
19 | #include "fake-lib.h" | 20 | #include "fake-lib.h" |
20 | 21 | ||
21 | typedef struct MsiTypePrefix { | 22 | typedef struct MsiTypePrefix { |
diff --git a/fake-winterop.c b/fake-winterop.c index 6f7e3d3..1b439fe 100644 --- a/fake-winterop.c +++ b/fake-winterop.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include "memory.h" | 14 | #include "memory.h" |
15 | #include "dupstr.h" | 15 | #include "dupstr.h" |
16 | #include "subproc.h" | ||
16 | #include "fake-lib.h" | 17 | #include "fake-lib.h" |
17 | 18 | ||
18 | uint32_t HashPublicKeyInfo(void *pCertContext, | 19 | uint32_t HashPublicKeyInfo(void *pCertContext, |
diff --git a/subproc.c b/subproc.c new file mode 100644 index 0000000..ae4991f --- /dev/null +++ b/subproc.c | |||
@@ -0,0 +1,59 @@ | |||
1 | #include <stddef.h> | ||
2 | #include <stdarg.h> | ||
3 | #include <string.h> | ||
4 | #include <err.h> | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <sys/wait.h> | ||
8 | #include <unistd.h> | ||
9 | |||
10 | #include "subproc.h" | ||
11 | |||
12 | void system_argv_array(char **args) | ||
13 | { | ||
14 | pid_t pid = fork(); | ||
15 | if (pid < 0) | ||
16 | err(1, "fork"); | ||
17 | |||
18 | if (pid == 0) { | ||
19 | execvp(args[0], args); | ||
20 | warn("execvp"); | ||
21 | _exit(127); | ||
22 | } | ||
23 | |||
24 | int status; | ||
25 | if (waitpid(pid, &status, 0) != pid) | ||
26 | err(1, "waitpid"); | ||
27 | if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) | ||
28 | errx(1, "subcommand failed"); | ||
29 | } | ||
30 | |||
31 | void system_argv(const char *cmd, ...) | ||
32 | { | ||
33 | int nargs, nchars; | ||
34 | const char *word; | ||
35 | va_list ap; | ||
36 | |||
37 | va_start(ap, cmd); | ||
38 | nargs = 1; /* terminating NULL */ | ||
39 | nchars = 0; | ||
40 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
41 | nargs++; | ||
42 | nchars += 1 + strlen(word); | ||
43 | } | ||
44 | va_end(ap); | ||
45 | |||
46 | char *args[nargs], chars[nchars]; | ||
47 | char **argp = args, *charp = chars; | ||
48 | va_start(ap, cmd); | ||
49 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
50 | *argp++ = charp; | ||
51 | strcpy(charp, word); | ||
52 | charp += 1 + strlen(word); | ||
53 | } | ||
54 | va_end(ap); | ||
55 | *argp++ = NULL; | ||
56 | |||
57 | system_argv_array(args); | ||
58 | } | ||
59 | |||
diff --git a/subproc.h b/subproc.h new file mode 100644 index 0000000..5f2d5f9 --- /dev/null +++ b/subproc.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef cNULL | ||
2 | #define cNULL ((const char *)NULL) | ||
3 | #endif | ||
4 | |||
5 | void system_argv(const char *cmd, ...); | ||
6 | void system_argv_array(char **args); | ||