update for HEAD-2003091401
[reactos.git] / lib / msvcrt / process / _cwait.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/msvcrt/process/cwait.c
5  * PURPOSE:     Waits for a process to exit 
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              04/03/99: Created
9  */
10 #include <windows.h>
11 #include <msvcrt/process.h>
12 #include <msvcrt/errno.h>
13 #include <msvcrt/internal/file.h>
14
15
16 /*
17  * @implemented
18  */
19 int _cwait(int* pnStatus, int hProc, int nAction)
20 {
21     DWORD ExitCode;
22
23         nAction = 0;
24         if (WaitForSingleObject((void*)hProc, INFINITE) != WAIT_OBJECT_0) {
25                 __set_errno(ECHILD);
26                 return -1;
27         }
28
29         if (!GetExitCodeProcess((void*)hProc, &ExitCode))
30                 return -1;
31         if (pnStatus != NULL)
32         *pnStatus = (int)ExitCode;
33     CloseHandle((HANDLE)hProc);
34     return hProc;
35 }