OSDN Git Service

ac2aeb33dddf66e32bf8725189b7bb7ab842462d
[pf3gnuchains/sourceware.git] / tcl / win / tclWinUtil.c
1 /* 
2  * tclWinUtil.c --
3  *
4  *      This file contains a collection of utility procedures that
5  *      are present in Tcl's Windows core but not in the generic
6  *      core.  For example, they do file manipulation and process
7  *      manipulation.
8  *
9  * Copyright (c) 1994-1996 Sun Microsystems, Inc.
10  *
11  * See the file "license.terms" for information on usage and redistribution
12  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13  *
14  * SCCS: @(#) tclWinUtil.c 1.9 96/01/16 10:31:48
15  */
16
17 #include "tclInt.h"
18 #include "tclPort.h"
19
20 \f
21 /*
22  *----------------------------------------------------------------------
23  *
24  * Tcl_WaitPid --
25  *
26  *      Does the waitpid system call.
27  *
28  * Results:
29  *      Returns return value of pid it's waiting for.
30  *
31  * Side effects:
32  *      None.
33  *
34  *----------------------------------------------------------------------
35  */
36
37 int
38 Tcl_WaitPid(pid, statPtr, options)
39     pid_t pid;
40     int *statPtr;
41     int options;
42 {
43     int flags;
44     DWORD ret;
45
46     if (options & WNOHANG) {
47         flags = 0;
48     } else {
49         flags = INFINITE;
50     }
51     ret = WaitForSingleObject((HANDLE)pid, flags);
52     if (ret == WAIT_TIMEOUT) {
53         *statPtr = 0;
54         return 0;
55     } else if (ret != WAIT_FAILED) {
56         GetExitCodeProcess((HANDLE)pid, (DWORD*)statPtr);
57         *statPtr = ((*statPtr << 8) & 0xff00);
58         CloseHandle((HANDLE)pid);
59         return pid;
60     } else {
61         errno = ECHILD;
62         return -1;
63     }
64 }
65
66