summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/winwait.c
blob: 5fe51f90f1fe34fd5355f3b8b4a51dadba33b0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*   Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt  */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  en Automatique.  Distributed only by permission.                   */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <windows.h>
#include <mlvalues.h>
#include <alloc.h>
#include <memory.h>
#include "unixsupport.h"
#include <sys/types.h>

static value alloc_process_status(HANDLE pid, int status)
{
  value res, st;

  st = alloc(1, 0);
  Field(st, 0) = Val_int(status);
  Begin_root (st);
    res = alloc_small(2, 0);
    Field(res, 0) = Val_long((long) pid);
    Field(res, 1) = st;
  End_roots();
  return res;
}

value win_waitpid(value flags, value vpid_req) /* ML */
{
  int status;
  HANDLE pid_req = (HANDLE) Long_val(vpid_req);

  if (WaitForSingleObject(pid_req, INFINITE) != WAIT_FAILED
      && GetExitCodeProcess(pid_req, &status)) {
    return alloc_process_status(pid_req, status);
  } else {
    _dosmaperr(GetLastError());
    uerror("waitpid", Nothing);
  }
}