[CRT] Adopt Wine Staging 1.7.37 _cwait() implementation. CORE-8214 CORE-9246
authorAmine Khaldi <amine.khaldi@reactos.org>
Fri, 10 Apr 2015 10:49:56 +0000 (10:49 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Fri, 10 Apr 2015 10:49:56 +0000 (10:49 +0000)
svn path=/trunk/; revision=67134

reactos/lib/sdk/crt/process/_cwait.c
reactos/media/doc/README.WINE

index 6ace44d..687b2e0 100644 (file)
@@ -3,30 +3,39 @@
  * PROJECT:     ReactOS system libraries
  * FILE:        lib/msvcrt/process/cwait.c
  * PURPOSE:     Waits for a process to exit
- * PROGRAMER:   Ariadne
- * UPDATE HISTORY:
- *              04/03/99: Created
  */
 
 #include <precomp.h>
 
+/* Taken from Wine msvcrt/process.c */
+
 /*
  * @implemented
  */
-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) {
-               _set_errno(ECHILD);
-               return -1;
-       }
+  if (doserrno == ERROR_INVALID_HANDLE)
+  {
+    *_errno() =  ECHILD;
+    *__doserrno() = doserrno;
+  }
+  else
+    _dosmaperr(doserrno);
 
-       if (!GetExitCodeProcess((void*)ULongToPtr(hProc), &ExitCode))
-               return -1;
-       if (pnStatus != NULL)
-        *pnStatus = (int)ExitCode;
-    CloseHandle((HANDLE)ULongToPtr(hProc));
-    return hProc;
+  return status ? *status = -1 : -1;
 }
index eecdc0e..6fc526b 100644 (file)
@@ -290,6 +290,7 @@ kernel32 -
 msvcrt -
   reactos/lib/sdk/crt/except/cpp.c              # Synced at 20080528
   reactos/lib/sdk/crt/except/cppexcept.c        # Synced at 20071111
+  reactos/lib/sdk/crt/process/_cwait.c          # Synced to WineStaging-1.7.37
   reactos/lib/sdk/crt/signal/xcptinfo.c         # Synced to Wine-1.7.17
   reactos/lib/sdk/crt/string/scanf.c/h          # Synced to Wine-1.7.17
   reactos/lib/sdk/crt/strings/wcs.c             # Synced at 20080611