ReactOS 0.4.16-dev-927-g467dec4
wait.cpp File Reference
#include <corecrt_internal.h>
#include <errno.h>
#include <process.h>
#include <stdlib.h>
Include dependency graph for wait.cpp:

Go to the source code of this file.

Functions

intptr_t __cdecl _cwait (int *const exit_code_result, intptr_t const process_id, int const action_code)
 

Function Documentation

◆ _cwait()

intptr_t __cdecl _cwait ( int *const  exit_code_result,
intptr_t const  process_id,
int const  action_code 
)

Definition at line 42 of file wait.cpp.

47{
48 DBG_UNREFERENCED_PARAMETER(action_code);
49
50 if (exit_code_result)
51 *exit_code_result = static_cast<DWORD>(-1);
52
53 // Explicitly check for process ids -1 and -2. In Windows NT, -1 is a handle
54 // to the current process and -2 is a handle to the current thread, and the
55 // OS will let you wait (forever) on either.
56 _VALIDATE_RETURN_NOEXC(process_id != -1 && process_id != -2, ECHILD, -1);
57
58 __crt_unique_handle process_handle(reinterpret_cast<HANDLE>(process_id));
59
60 // Wait for the child process and get its exit code:
62 if (WaitForSingleObject(process_handle.get(), static_cast<DWORD>(-1)) == 0 &&
63 GetExitCodeProcess(process_handle.get(), &exit_code))
64 {
65 if (exit_code_result)
66 *exit_code_result = exit_code;
67
68 return process_id;
69 }
70
71 // One of the API calls failed; map the error and return failure.
72 DWORD const os_error = GetLastError();
73 if (os_error == ERROR_INVALID_HANDLE)
74 {
75 errno = ECHILD;
76 _doserrno = os_error;
77 }
78 else
79 {
81 }
82
83 if (exit_code_result)
84 *exit_code_result = static_cast<DWORD>(-1);
85
86 return -1;
87}
void __cdecl __acrt_errno_map_os_error(unsigned long)
Definition: errno.cpp:91
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
#define ECHILD
Definition: errno.h:16
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _doserrno
Definition: stdlib.h:131
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
static UINT exit_code
Definition: process.c:78
#define DBG_UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:326
#define errno
Definition: errno.h:18
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI GetLastError(void)
Definition: except.c:1042