aboutsummaryrefslogtreecommitdiff
path: root/fake-msi.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-18 07:03:04 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-18 07:10:17 +0100
commit48919caa7b9fb99ba8196098c0ca2e1b3dae5160 (patch)
tree585312e8c0182016e99d8bb35ba12e1c1115ab09 /fake-msi.c
parent69d886c5757e405785ce811d8622f4ff189a9514 (diff)
downloadwix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.tar.gz
wix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.tar.bz2
wix-on-linux-48919caa7b9fb99ba8196098c0ca2e1b3dae5160.zip
Move dupcat out into its own file, and add dupstr.
Also a handy #define to replace all those tedious castings of NULL.
Diffstat (limited to 'fake-msi.c')
-rw-r--r--fake-msi.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/fake-msi.c b/fake-msi.c
index 2223211..12b1489 100644
--- a/fake-msi.c
+++ b/fake-msi.c
@@ -15,6 +15,7 @@
15#include <unistd.h> 15#include <unistd.h>
16 16
17#include "memory.h" 17#include "memory.h"
18#include "dupstr.h"
18#include "fake-lib.h" 19#include "fake-lib.h"
19 20
20typedef struct MsiTypePrefix { 21typedef struct MsiTypePrefix {
@@ -42,19 +43,18 @@ uint32_t MsiOpenDatabaseW(const char16_t *filename,
42 close(open(ctx->outfile, O_CREAT | O_WRONLY, 0666)); 43 close(open(ctx->outfile, O_CREAT | O_WRONLY, 0666));
43 ctx->outfile = realpath(ctx->outfile, NULL); 44 ctx->outfile = realpath(ctx->outfile, NULL);
44 unlink(ctx->outfile); 45 unlink(ctx->outfile);
45 ctx->tempdir = dupcat(ctx->outfile, "-msiXXXXXX", (const char *)NULL); 46 ctx->tempdir = dupcat(ctx->outfile, "-msiXXXXXX", cNULL);
46 if (!mkdtemp(ctx->tempdir)) 47 if (!mkdtemp(ctx->tempdir))
47 err(1, "%s: mkdtemp", ctx->tempdir); 48 err(1, "%s: mkdtemp", ctx->tempdir);
48 ctx->nargs = 0; 49 ctx->nargs = 0;
49 ctx->argsize = 16; 50 ctx->argsize = 16;
50 ctx->args = snewn(ctx->argsize, char *); 51 ctx->args = snewn(ctx->argsize, char *);
51 ctx->args[ctx->nargs++] = dupcat("sh", (const char *)NULL); 52 ctx->args[ctx->nargs++] = dupstr("sh");
52 ctx->args[ctx->nargs++] = dupcat("-c", (const char *)NULL); 53 ctx->args[ctx->nargs++] = dupstr("-c");
53 ctx->args[ctx->nargs++] = dupcat("cd \"$0\" && \"$@\"", 54 ctx->args[ctx->nargs++] = dupstr("cd \"$0\" && \"$@\"");
54 (const char *)NULL); 55 ctx->args[ctx->nargs++] = dupstr(ctx->tempdir);
55 ctx->args[ctx->nargs++] = dupcat(ctx->tempdir, (const char *)NULL); 56 ctx->args[ctx->nargs++] = dupstr("msibuild");
56 ctx->args[ctx->nargs++] = dupcat("msibuild", (const char *)NULL); 57 ctx->args[ctx->nargs++] = dupstr(ctx->outfile);
57 ctx->args[ctx->nargs++] = dupcat(ctx->outfile, (const char *)NULL);
58 *out_ctx = ctx; 58 *out_ctx = ctx;
59 return 0; 59 return 0;
60} 60}
@@ -64,15 +64,14 @@ uint32_t MsiDatabaseImportW(MsiMainCtx *ctx, const char16_t *folder,
64{ 64{
65 assert(ctx->t.type == MAIN); 65 assert(ctx->t.type == MAIN);
66 system_argv("sh", "-c", "cd \"$0\" && cp \"$1\" \"$2\"", 66 system_argv("sh", "-c", "cd \"$0\" && cp \"$1\" \"$2\"",
67 ascii(folder, true), ascii(file, true), ctx->tempdir, 67 ascii(folder, true), ascii(file, true), ctx->tempdir, cNULL);
68 (const char *)NULL);
69 if (ctx->nargs + 2 >= ctx->argsize) { 68 if (ctx->nargs + 2 >= ctx->argsize) {
70 ctx->argsize = ctx->nargs * 5 / 4 + 16; 69 ctx->argsize = ctx->nargs * 5 / 4 + 16;
71 ctx->args = sresize(ctx->args, ctx->argsize, char *); 70 ctx->args = sresize(ctx->args, ctx->argsize, char *);
72 } 71 }
73 ctx->args[ctx->nargs++] = dupcat("-i", (const char *)NULL); 72 ctx->args[ctx->nargs++] = dupstr("-i");
74 ctx->args[ctx->nargs++] = dupcat(ctx->tempdir, "/", ascii(file, true), 73 ctx->args[ctx->nargs++] = dupcat(ctx->tempdir, "/", ascii(file, true),
75 (const char *)NULL); 74 cNULL);
76 return 0; 75 return 0;
77} 76}
78 77
@@ -96,15 +95,13 @@ uint32_t MsiDatabaseOpenViewW(MsiMainCtx *ctx, const char16_t *query,
96 view->fp = NULL; /* special case */ 95 view->fp = NULL; /* special case */
97 else { 96 else {
98 if (!strcmp(cquery, "SELECT `Name`, `Data` FROM `Binary`")) { 97 if (!strcmp(cquery, "SELECT `Name`, `Data` FROM `Binary`")) {
99 view->fp = fopen(dupcat(ctx->tempdir, "/", "Binary.idt", 98 view->fp = fopen(dupcat(ctx->tempdir, "/", "Binary.idt", cNULL),
100 (const char *)NULL), "a"); 99 "a");
101 view->targetdir = dupcat(ctx->tempdir, "/", "Binary", 100 view->targetdir = dupcat(ctx->tempdir, "/", "Binary", cNULL);
102 (const char *)NULL);
103 } else if (!strcmp(cquery, "SELECT `Name`, `Data` FROM `Icon`")) { 101 } else if (!strcmp(cquery, "SELECT `Name`, `Data` FROM `Icon`")) {
104 view->fp = fopen(dupcat(ctx->tempdir, "/", "Icon.idt", 102 view->fp = fopen(dupcat(ctx->tempdir, "/", "Icon.idt", cNULL),
105 (const char *)NULL), "a"); 103 "a");
106 view->targetdir = dupcat(ctx->tempdir, "/", "Icon", 104 view->targetdir = dupcat(ctx->tempdir, "/", "Icon", cNULL);
107 (const char *)NULL);
108 } else 105 } else
109 errx(1, "unrecognised query: %s", cquery); 106 errx(1, "unrecognised query: %s", cquery);
110 if (!view->fp) 107 if (!view->fp)
@@ -163,8 +160,7 @@ uint32_t MsiViewModify(MsiView *view, uint32_t mode, MsiRecord *rec)
163 assert(rec->t.type == RECORD); 160 assert(rec->t.type == RECORD);
164 if (view->fp) { 161 if (view->fp) {
165 system_argv("sh", "-c", "cp \"$0\" \"$1\"/\"$2\"", 162 system_argv("sh", "-c", "cp \"$0\" \"$1\"/\"$2\"",
166 rec->data, view->targetdir, rec->name, 163 rec->data, view->targetdir, rec->name, cNULL);
167 (const char *)NULL);
168 fprintf(view->fp, "%s\t%s\r\n", rec->name, rec->name); 164 fprintf(view->fp, "%s\t%s\r\n", rec->name, rec->name);
169 } else { 165 } else {
170 MsiMainCtx *ctx = view->ctx; 166 MsiMainCtx *ctx = view->ctx;
@@ -172,9 +168,9 @@ uint32_t MsiViewModify(MsiView *view, uint32_t mode, MsiRecord *rec)
172 ctx->argsize = ctx->nargs * 5 / 4 + 16; 168 ctx->argsize = ctx->nargs * 5 / 4 + 16;
173 ctx->args = sresize(ctx->args, ctx->argsize, char *); 169 ctx->args = sresize(ctx->args, ctx->argsize, char *);
174 } 170 }
175 ctx->args[ctx->nargs++] = dupcat("-a", (const char *)NULL); 171 ctx->args[ctx->nargs++] = dupstr("-a");
176 ctx->args[ctx->nargs++] = dupcat(rec->name, (const char *)NULL); 172 ctx->args[ctx->nargs++] = dupstr(rec->name);
177 ctx->args[ctx->nargs++] = dupcat(rec->data, (const char *)NULL); 173 ctx->args[ctx->nargs++] = dupstr(rec->data);
178 } 174 }
179 return 0; 175 return 0;
180} 176}