| 391 | } |
| 392 | |
| 393 | int cbm_pclose(FILE *f) { |
| 394 | InitOnceExecuteOnce(&g_popen_once, cbm_popen_init, NULL, NULL); |
| 395 | |
| 396 | HANDLE proc = NULL; |
| 397 | EnterCriticalSection(&g_popen_lock); |
| 398 | for (int i = 0; i < CBM_POPEN_MAX; i++) { |
| 399 | if (g_popen_tab[i].fp == f) { |
| 400 | proc = g_popen_tab[i].proc; |
| 401 | g_popen_tab[i].fp = NULL; |
| 402 | g_popen_tab[i].proc = NULL; |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | LeaveCriticalSection(&g_popen_lock); |
| 407 | |
| 408 | if (!proc) { |
| 409 | return _pclose(f); /* opened via _popen (non-read mode) */ |
| 410 | } |
| 411 | fclose(f); |
| 412 | WaitForSingleObject(proc, INFINITE); |
| 413 | DWORD code = 0; |
| 414 | BOOL got = GetExitCodeProcess(proc, &code); |
| 415 | CloseHandle(proc); |
| 416 | return got ? (int)code : -1; |
| 417 | } |
| 418 | |
| 419 | FILE *cbm_fopen(const char *path, const char *mode) { |
| 420 | wchar_t *wpath = cbm_path_to_wide(path); |
no outgoing calls
no test coverage detected