aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-18 07:09:40 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-18 07:10:17 +0100
commit3b3a5fd6bf7a3542ab8e8701c93c3d0f505c722f (patch)
tree5d8299dec3ce144bb5765382b6268fb39a856542
parent48919caa7b9fb99ba8196098c0ca2e1b3dae5160 (diff)
downloadwix-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.am6
-rw-r--r--dupstr.h2
-rw-r--r--fake-lib.c52
-rw-r--r--fake-lib.h2
-rw-r--r--fake-msi.c1
-rw-r--r--fake-winterop.c1
-rw-r--r--subproc.c59
-rw-r--r--subproc.h6
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
5lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la 5lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la
6 6
7libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ 7libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \
8memory.c memory.h dupstr.c dupstr.h 8memory.c memory.h dupstr.c dupstr.h subproc.c subproc.h
9 9
10libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ 10libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \
11memory.c memory.h version.c dupstr.c dupstr.h 11memory.c memory.h version.c dupstr.c dupstr.h subproc.c subproc.h
12 12
13libpreload_la_SOURCES = preload.c 13libpreload_la_SOURCES = preload.c
14libpreload_la_LDFLAGS = -ldl 14libpreload_la_LDFLAGS = -ldl
diff --git a/dupstr.h b/dupstr.h
index ea152c5..fd29bb1 100644
--- a/dupstr.h
+++ b/dupstr.h
@@ -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
5char *dupstr(const char *str); 7char *dupstr(const char *str);
6char *dupcat(const char *str, ...); 8char *dupcat(const char *str, ...);
diff --git a/fake-lib.c b/fake-lib.c
index cf6be49..e2bc364 100644
--- a/fake-lib.c
+++ b/fake-lib.c
@@ -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
32void 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
51void 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
80void c16cpy(char16_t *out, uint32_t *outsize, char *s) 28void c16cpy(char16_t *out, uint32_t *outsize, char *s)
81{ 29{
82 uint32_t retlen = 0; 30 uint32_t retlen = 0;
diff --git a/fake-lib.h b/fake-lib.h
index c71b977..5ae4a91 100644
--- a/fake-lib.h
+++ b/fake-lib.h
@@ -2,6 +2,4 @@
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4char *ascii(const char16_t *wstr, bool translate_slashes); 4char *ascii(const char16_t *wstr, bool translate_slashes);
5void system_argv(const char *cmd, ...);
6void system_argv_array(char **args);
7void c16cpy(char16_t *out, uint32_t *outsize, char *s); 5void c16cpy(char16_t *out, uint32_t *outsize, char *s);
diff --git a/fake-msi.c b/fake-msi.c
index 12b1489..0600671 100644
--- a/fake-msi.c
+++ b/fake-msi.c
@@ -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
21typedef struct MsiTypePrefix { 22typedef 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
18uint32_t HashPublicKeyInfo(void *pCertContext, 19uint32_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
12void 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
31void 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
5void system_argv(const char *cmd, ...);
6void system_argv_array(char **args);