The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Factor out the exec code in stdlib/header.c

+38 -26
+38 -26
stdlib/header.c
··· 60 60 return FALSE; 61 61 } 62 62 63 + static void exec_file(wchar_t *file, wchar_t *cmdline) 64 + { 65 + wchar_t truename[MAX_PATH]; 66 + STARTUPINFO stinfo; 67 + PROCESS_INFORMATION procinfo; 68 + DWORD retcode; 69 + 70 + if (SearchPath(NULL, file, L".exe", sizeof(truename)/sizeof(wchar_t), 71 + truename, NULL)) { 72 + /* Need to ignore ctrl-C and ctrl-break, otherwise we'll die and take the 73 + underlying OCaml program with us! */ 74 + SetConsoleCtrlHandler(ctrl_handler, TRUE); 75 + 76 + stinfo.cb = sizeof(stinfo); 77 + stinfo.lpReserved = NULL; 78 + stinfo.lpDesktop = NULL; 79 + stinfo.lpTitle = NULL; 80 + stinfo.dwFlags = 0; 81 + stinfo.cbReserved2 = 0; 82 + stinfo.lpReserved2 = NULL; 83 + if (CreateProcess(truename, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, 84 + &stinfo, &procinfo)) { 85 + CloseHandle(procinfo.hThread); 86 + WaitForSingleObject(procinfo.hProcess, INFINITE); 87 + GetExitCodeProcess(procinfo.hProcess, &retcode); 88 + CloseHandle(procinfo.hProcess); 89 + ExitProcess(retcode); 90 + } 91 + } 92 + } 93 + 63 94 static void write_error(const wchar_t *wstr, HANDLE hOut) 64 95 { 65 96 DWORD consoleMode, numwritten, len; ··· 198 229 exit(2); 199 230 } 200 231 232 + static void exec_file(const char *file, char * const argv[]) 233 + { 234 + execvp(file, argv); 235 + } 236 + 201 237 #endif /* defined(_WIN32) */ 202 238 203 239 #define CAML_INTERNALS ··· 248 284 char *runtime_path; 249 285 wchar_t wruntime_path[MAX_PATH]; 250 286 HANDLE h; 251 - STARTUPINFO stinfo; 252 - PROCESS_INFORMATION procinfo; 253 - DWORD retcode; 254 287 255 288 if (GetModuleFileName(NULL, truename, sizeof(truename)/sizeof(wchar_t)) == 0) 256 289 exit_with_error(L"Out of memory", NULL, NULL); ··· 264 297 exit_with_error(NULL, truename, 265 298 L" not found or is not a bytecode executable file"); 266 299 CloseHandle(h); 267 - if (SearchPath(NULL, wruntime_path, L".exe", sizeof(truename)/sizeof(wchar_t), 268 - truename, NULL)) { 269 - /* Need to ignore ctrl-C and ctrl-break, otherwise we'll die and take 270 - the underlying OCaml program with us! */ 271 - SetConsoleCtrlHandler(ctrl_handler, TRUE); 272 - 273 - stinfo.cb = sizeof(stinfo); 274 - stinfo.lpReserved = NULL; 275 - stinfo.lpDesktop = NULL; 276 - stinfo.lpTitle = NULL; 277 - stinfo.dwFlags = 0; 278 - stinfo.cbReserved2 = 0; 279 - stinfo.lpReserved2 = NULL; 280 - if (CreateProcess(truename, GetCommandLine(), NULL, NULL, TRUE, 0, 281 - NULL, NULL, &stinfo, &procinfo)) { 282 - CloseHandle(procinfo.hThread); 283 - WaitForSingleObject(procinfo.hProcess, INFINITE); 284 - GetExitCodeProcess(procinfo.hProcess, &retcode); 285 - CloseHandle(procinfo.hProcess); 286 - ExitProcess(retcode); 287 - } 288 - } 300 + exec_file(wruntime_path, GetCommandLine()); 289 301 290 302 exit_with_error(L"Cannot exec ", wruntime_path, NULL); 291 303 } ··· 305 317 close(fd); 306 318 307 319 argv[0] = truename; 308 - execvp(runtime_path, argv); 320 + exec_file(runtime_path, argv); 309 321 310 322 exit_with_error("Cannot exec ", runtime_path, NULL); 311 323 }