Index: lib/sdk/crt/process/_cwait.c =================================================================== --- lib/sdk/crt/process/_cwait.c (revision 63250) +++ lib/sdk/crt/process/_cwait.c (working copy) @@ -1,32 +1,40 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries - * FILE: lib/msvcrt/process/cwait.c + * FILE: lib/msvcrt/process/_cwait.c * PURPOSE: Waits for a process to exit - * PROGRAMER: Ariadne - * UPDATE HISTORY: - * 04/03/99: Created + * PROGRAMER: + * UPDATE HISTORY: Synced with wine 1.7.18 + * */ #include -/* - * @implemented +/********************************************************************* + * _cwait (MSVCRT.@) */ -int _cwait(int* pnStatus, int hProc, int nAction) +intptr_t CDECL _cwait(int *status, intptr_t pid, int action) { - DWORD ExitCode; + HANDLE hPid = (HANDLE)pid; + int doserrno; + if (!WaitForSingleObject(hPid, INFINITE)) + { + if (status) + { + DWORD stat; + GetExitCodeProcess(hPid, &stat); + *status = (int)stat; + } + return pid; + } + doserrno = GetLastError(); - nAction = 0; - if (WaitForSingleObject((void*)ULongToPtr(hProc), INFINITE) != WAIT_OBJECT_0) { + if (doserrno == ERROR_INVALID_HANDLE) + { _set_errno(ECHILD); - return -1; + _set_doserrno(doserrno); } - - if (!GetExitCodeProcess((void*)ULongToPtr(hProc), &ExitCode)) - return -1; - if (pnStatus != NULL) - *pnStatus = (int)ExitCode; - CloseHandle((HANDLE)ULongToPtr(hProc)); - return hProc; + else + _set_doserrno(doserrno); + return status ? *status = -1 : -1; }