FIX profiling after my storage manager changes
[ghc.git] / InstallShield / runexe.c
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <windows.h>
4
5 const char *prog = "runexe";
6
7 #define BUFLEN 65537
8
9 void die(char *fmt, ...)
10 {
11 va_list ap = va_start(ap, fmt);
12
13 fprintf(stderr, "%s: ", prog);
14 vfprintf(stderr, fmt, ap);
15 fprintf(stderr, "\n");
16 va_end(ap);
17 exit(1);
18 }
19
20 void warn(char *fmt, ...)
21 {
22 va_list ap = va_start(ap, fmt);
23
24 fprintf(stderr, "%s: ", prog);
25 vfprintf(stderr, fmt, ap);
26 fprintf(stderr, "\n");
27 va_end(ap);
28 }
29
30 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
31 {
32 STARTUPINFO sInfo;
33 PROCESS_INFORMATION pInfo;
34 TCHAR buf[BUFLEN];
35 DWORD retCode;
36
37 sInfo.cb = sizeof(STARTUPINFO);
38 sInfo.lpReserved = NULL;
39 sInfo.lpReserved2 = NULL;
40 sInfo.cbReserved2 = 0;
41 sInfo.lpDesktop = NULL;
42 sInfo.lpTitle = NULL;
43 sInfo.dwFlags = 0;
44
45 if (GetCurrentDirectory(BUFLEN, buf) == 0) die("couldn't get current directory");
46 if (strlen(lpszCmdParam) == 0) die("no parameters given");
47 warn("cwd: %s\n", buf);
48 warn("runexing >>>%s<<<\n", lpszCmdParam);
49 if (!CreateProcess(NULL, lpszCmdParam, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
50 die("could not create process");
51
52 WaitForSingleObject(pInfo.hProcess, INFINITE);
53 if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) retCode = -1;
54 CloseHandle(pInfo.hProcess);
55 CloseHandle(pInfo.hThread);
56 printf("return code %ld\n", retCode);
57
58 return retCode;
59 }