summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-02-01 11:27:43 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-02-01 11:27:43 (GMT)
commitab034fab03bf1a0ee1d03651799f1c42f4f48050 (patch)
treef3669466f351c8155095e2c849ebc8352d07e6eb /Modules/posixmodule.c
parent0c350bfad0ec9350aec57e37962b1aadb8492173 (diff)
downloadcpython-ab034fab03bf1a0ee1d03651799f1c42f4f48050.zip
cpython-ab034fab03bf1a0ee1d03651799f1c42f4f48050.tar.gz
cpython-ab034fab03bf1a0ee1d03651799f1c42f4f48050.tar.bz2
Implement os.waitpid() for Windows, in a way that's compatible with Linux
where their capabilities intersect. Would be nice if people using non- MSVC compilers (Borland etc) took a whack at doing something similar for them (this code relies on the MS _cwait function).
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 77b0d66..40cf5a7 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -78,6 +78,7 @@ corresponding Unix manual entries for more information on calls.";
#define HAVE_PIPE 1
#define HAVE_POPEN 1
#define HAVE_SYSTEM 1
+#define HAVE_CWAIT 1
#else /* 16-bit Windows */
#endif /* !MS_WIN32 */
#else /* all other compilers */
@@ -3333,8 +3334,33 @@ posix_waitpid(PyObject *self, PyObject *args)
else
return Py_BuildValue("ii", pid, status_i);
}
-#endif /* HAVE_WAITPID */
+#elif defined(HAVE_CWAIT)
+
+/* MS C has a variant of waitpid() that's usable for most purposes. */
+static char posix_waitpid__doc__[] =
+"waitpid(pid, options) -> (pid, status << 8)\n"
+"Wait for completion of a given process. options is ignored on Windows.";
+
+static PyObject *
+posix_waitpid(PyObject *self, PyObject *args)
+{
+ int pid, options;
+ int status;
+
+ if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ pid = _cwait(&status, pid, options);
+ Py_END_ALLOW_THREADS
+ if (pid == -1)
+ return posix_error();
+ else
+ /* shift the status left a byte so this is more like the
+ POSIX waitpid */
+ return Py_BuildValue("ii", pid, status << 8);
+}
+#endif /* HAVE_WAITPID || HAVE_CWAIT */
#ifdef HAVE_WAIT
static char posix_wait__doc__[] =
@@ -5678,7 +5704,7 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_WAIT
{"wait", posix_wait, METH_VARARGS, posix_wait__doc__},
#endif /* HAVE_WAIT */
-#ifdef HAVE_WAITPID
+#if defined(HAVE_WAITPID) || defined(HAVE_CWAIT)
{"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__},
#endif /* HAVE_WAITPID */
#ifdef HAVE_SETSID