2 /* gcc on mingw is hardcoded to use /mingw (which is c:/mingw) to
3 find various files. If this is a different version of mingw to the
4 one that we have in the GHC tree then things can go wrong. We
5 therefore need to add various -B flags to the gcc commandline,
6 so that it uses our in-tree mingw. Hence this wrapper. */
16 void die(const char *fmt, ...) {
20 vfprintf(stderr, fmt, argp);
25 char *mkString(const char *fmt, ...) {
31 i = vsnprintf(NULL, 0, fmt, argp);
35 die("snprintf 0 failed: errno %d: %s\n", errno, strerror(errno));
40 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
44 j = vsnprintf(p, i + 1, fmt, argp);
47 die("snprintf with %d failed: errno %d: %s\n",
48 i + 1, errno, strerror(errno));
54 char *quote(char *str) {
58 quotedStr = malloc(2 * strlen(str) + 2 + 1);
59 if (quotedStr == NULL) {
60 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
76 __attribute__((noreturn)) int run(char *exePath, int numArgs1, char **args1, int numArgs2, char **args2) {
81 newArgv = malloc(sizeof(char *) * (1 + numArgs1 + numArgs2 + 1));
82 if (newArgv == NULL) {
83 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
86 *p++ = quote(exePath);
87 for (i = 0; i < numArgs1; i++) {
88 *p++ = quote(args1[i]);
90 for (i = 0; i < numArgs2; i++) {
91 *p++ = quote(args2[i]);
94 ret = spawnv(_P_WAIT, exePath, (const char* const*)newArgv);
96 die("spawnv failed: errno %d: %s\n", errno, strerror(errno));