diff options
author | Simon Tatham <anakin@pobox.com> | 2017-05-15 18:46:48 +0100 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2017-05-15 18:46:48 +0100 |
commit | d6e5f7ae7b48fd09a366a6fa7efaf9b72d40275f (patch) | |
tree | da6a72a982d1ca0b0b198cb342b116ccf99c656a /fake-lib.c | |
parent | 6824aa549cbfc535debee2effe99b5a30849fdcd (diff) | |
download | wix-on-linux-d6e5f7ae7b48fd09a366a6fa7efaf9b72d40275f.tar.gz wix-on-linux-d6e5f7ae7b48fd09a366a6fa7efaf9b72d40275f.tar.bz2 wix-on-linux-d6e5f7ae7b48fd09a366a6fa7efaf9b72d40275f.zip |
All the remaining function stubs I appear to need.
Now I can get an idea of what sequence of calls WiX actually expects
to use to build an MSI.
Diffstat (limited to 'fake-lib.c')
-rw-r--r-- | fake-lib.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/fake-lib.c b/fake-lib.c new file mode 100644 index 0000000..f8dbea4 --- /dev/null +++ b/fake-lib.c | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <stdint.h> | ||
4 | #include <stdbool.h> | ||
5 | #include <stdarg.h> | ||
6 | #include <string.h> | ||
7 | #include <uchar.h> | ||
8 | #include <err.h> | ||
9 | |||
10 | #include <sys/types.h> | ||
11 | #include <sys/wait.h> | ||
12 | #include <unistd.h> | ||
13 | |||
14 | static char *ascii(const char16_t *wstr, bool translate_slashes) | ||
15 | { | ||
16 | size_t len = 0; | ||
17 | for (const char16_t *wp = wstr; *wp; wp++) | ||
18 | len++; | ||
19 | char *ret = malloc(len + 1); | ||
20 | char *p = ret; | ||
21 | for (const char16_t *wp = wstr; *wp; wp++) | ||
22 | *p++ = (*wp == '\\' && translate_slashes ? '/' : | ||
23 | *wp < 0x80 ? *wp : | ||
24 | '?'); | ||
25 | *p = '\0'; | ||
26 | return ret; | ||
27 | } | ||
28 | |||
29 | static void system_argv(const char *cmd, ...) | ||
30 | { | ||
31 | int nargs, nchars; | ||
32 | const char *word; | ||
33 | va_list ap; | ||
34 | |||
35 | va_start(ap, cmd); | ||
36 | nargs = 1; /* terminating NULL */ | ||
37 | nchars = 0; | ||
38 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
39 | nargs++; | ||
40 | nchars += 1 + strlen(word); | ||
41 | } | ||
42 | va_end(ap); | ||
43 | |||
44 | char *args[nargs], chars[nchars]; | ||
45 | char **argp = args, *charp = chars; | ||
46 | va_start(ap, cmd); | ||
47 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
48 | *argp++ = charp; | ||
49 | strcpy(charp, word); | ||
50 | charp += 1 + strlen(word); | ||
51 | } | ||
52 | va_end(ap); | ||
53 | *argp++ = NULL; | ||
54 | |||
55 | pid_t pid = fork(); | ||
56 | if (pid < 0) | ||
57 | err(1, "fork"); | ||
58 | |||
59 | if (pid == 0) { | ||
60 | execvp(args[0], args); | ||
61 | warn("execvp"); | ||
62 | _exit(127); | ||
63 | } | ||
64 | |||
65 | int status; | ||
66 | if (waitpid(pid, &status, 0) != pid) | ||
67 | err(1, "waitpid"); | ||
68 | if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) | ||
69 | errx(1, "subcommand failed"); | ||
70 | } | ||