]> git.proxmox.com Git - mirror_edk2.git/commitdiff
AppPkg/.../Python-2.7.10: Remove irrelevant conditional code from edk2module.c.
authorDaryl McDaniel <edk2-lists@mc2research.org>
Wed, 23 Dec 2015 00:01:30 +0000 (00:01 +0000)
committerdarylm503 <darylm503@Edk2>
Wed, 23 Dec 2015 00:01:30 +0000 (00:01 +0000)
Remove sections of conditional code that are not relevant to the
EDK II or UEFI environments.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <edk2-lists@mc2research.org>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19459 6f19259b-4bc3-4df7-8a09-765794883524

AppPkg/Applications/Python/Python-2.7.10/PyMod-2.7.10/Modules/edk2module.c

index 037849504f0f086d480138cb0f4a747f3fddb8f7..9460a50bc5e614284bbcc60ec6ad074ea1e5b0e0 100644 (file)
@@ -1060,61 +1060,6 @@ posix_listdir(PyObject *self, PyObject *args)
 \r
 }  /* end of posix_listdir */\r
 \r
 \r
 }  /* end of posix_listdir */\r
 \r
-#ifdef MS_WINDOWS\r
-/* A helper function for abspath on win32 */\r
-static PyObject *\r
-posix__getfullpathname(PyObject *self, PyObject *args)\r
-{\r
-    /* assume encoded strings won't more than double no of chars */\r
-    char inbuf[MAX_PATH*2];\r
-    char *inbufp = inbuf;\r
-    Py_ssize_t insize = sizeof(inbuf);\r
-    char outbuf[MAX_PATH*2];\r
-    char *temp;\r
-\r
-    PyUnicodeObject *po;\r
-    if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {\r
-        Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);\r
-        Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf;\r
-        Py_UNICODE *wtemp;\r
-        DWORD result;\r
-        PyObject *v;\r
-        result = GetFullPathNameW(wpath,\r
-                                  sizeof(woutbuf)/sizeof(woutbuf[0]),\r
-                                  woutbuf, &wtemp);\r
-        if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {\r
-            woutbufp = malloc(result * sizeof(Py_UNICODE));\r
-            if (!woutbufp)\r
-                return PyErr_NoMemory();\r
-            result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);\r
-        }\r
-        if (result)\r
-            v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp));\r
-        else\r
-            v = win32_error_unicode("GetFullPathNameW", wpath);\r
-        if (woutbufp != woutbuf)\r
-            free(woutbufp);\r
-        return v;\r
-    }\r
-    /* Drop the argument parsing error as narrow strings\r
-       are also valid. */\r
-    PyErr_Clear();\r
-\r
-    if (!PyArg_ParseTuple (args, "et#:_getfullpathname",\r
-                           Py_FileSystemDefaultEncoding, &inbufp,\r
-                           &insize))\r
-        return NULL;\r
-    if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]),\r
-                         outbuf, &temp))\r
-        return win32_error("GetFullPathName", inbuf);\r
-    if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {\r
-        return PyUnicode_Decode(outbuf, strlen(outbuf),\r
-                                Py_FileSystemDefaultEncoding, NULL);\r
-    }\r
-    return PyString_FromString(outbuf);\r
-} /* end of posix__getfullpathname */\r
-#endif /* MS_WINDOWS */\r
-\r
 PyDoc_STRVAR(posix_mkdir__doc__,\r
 "mkdir(path [, mode=0777])\n\n\\r
 Create a directory.");\r
 PyDoc_STRVAR(posix_mkdir__doc__,\r
 "mkdir(path [, mode=0777])\n\n\\r
 Create a directory.");\r
@@ -2293,45 +2238,6 @@ posix_forkpty(PyObject *self, PyObject *noargs)
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifdef HAVE_GETEGID\r
-PyDoc_STRVAR(posix_getegid__doc__,\r
-"getegid() -> egid\n\n\\r
-Return the current process's effective group id.");\r
-\r
-static PyObject *\r
-posix_getegid(PyObject *self, PyObject *noargs)\r
-{\r
-    return PyInt_FromLong((long)getegid());\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_GETEUID\r
-PyDoc_STRVAR(posix_geteuid__doc__,\r
-"geteuid() -> euid\n\n\\r
-Return the current process's effective user id.");\r
-\r
-static PyObject *\r
-posix_geteuid(PyObject *self, PyObject *noargs)\r
-{\r
-    return PyInt_FromLong((long)geteuid());\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_GETGID\r
-PyDoc_STRVAR(posix_getgid__doc__,\r
-"getgid() -> gid\n\n\\r
-Return the current process's group id.");\r
-\r
-static PyObject *\r
-posix_getgid(PyObject *self, PyObject *noargs)\r
-{\r
-    return PyInt_FromLong((long)getgid());\r
-}\r
-#endif\r
-\r
-\r
 PyDoc_STRVAR(posix_getpid__doc__,\r
 "getpid() -> pid\n\n\\r
 Return the current process id");\r
 PyDoc_STRVAR(posix_getpid__doc__,\r
 "getpid() -> pid\n\n\\r
 Return the current process id");\r
@@ -2342,177 +2248,6 @@ posix_getpid(PyObject *self, PyObject *noargs)
     return PyLong_FromPid(getpid());\r
 }\r
 \r
     return PyLong_FromPid(getpid());\r
 }\r
 \r
-\r
-#ifdef HAVE_GETGROUPS\r
-PyDoc_STRVAR(posix_getgroups__doc__,\r
-"getgroups() -> list of group IDs\n\n\\r
-Return list of supplemental group IDs for the process.");\r
-\r
-static PyObject *\r
-posix_getgroups(PyObject *self, PyObject *noargs)\r
-{\r
-    PyObject *result = NULL;\r
-\r
-#ifdef NGROUPS_MAX\r
-#define MAX_GROUPS NGROUPS_MAX\r
-#else\r
-    /* defined to be 16 on Solaris7, so this should be a small number */\r
-#define MAX_GROUPS 64\r
-#endif\r
-    gid_t grouplist[MAX_GROUPS];\r
-\r
-    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results\r
-     * This is a helper variable to store the intermediate result when\r
-     * that happens.\r
-     *\r
-     * To keep the code readable the OSX behaviour is unconditional,\r
-     * according to the POSIX spec this should be safe on all unix-y\r
-     * systems.\r
-     */\r
-    gid_t* alt_grouplist = grouplist;\r
-    int n;\r
-\r
-    n = getgroups(MAX_GROUPS, grouplist);\r
-    if (n < 0) {\r
-        if (errno == EINVAL) {\r
-            n = getgroups(0, NULL);\r
-            if (n == -1) {\r
-                return posix_error();\r
-            }\r
-            if (n == 0) {\r
-                /* Avoid malloc(0) */\r
-                alt_grouplist = grouplist;\r
-            } else {\r
-                alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));\r
-                if (alt_grouplist == NULL) {\r
-                    errno = EINVAL;\r
-                    return posix_error();\r
-                }\r
-                n = getgroups(n, alt_grouplist);\r
-                if (n == -1) {\r
-                    PyMem_Free(alt_grouplist);\r
-                    return posix_error();\r
-                }\r
-            }\r
-        } else {\r
-            return posix_error();\r
-        }\r
-    }\r
-    result = PyList_New(n);\r
-    if (result != NULL) {\r
-        int i;\r
-        for (i = 0; i < n; ++i) {\r
-            PyObject *o = PyInt_FromLong((long)alt_grouplist[i]);\r
-            if (o == NULL) {\r
-                Py_DECREF(result);\r
-                result = NULL;\r
-                break;\r
-            }\r
-            PyList_SET_ITEM(result, i, o);\r
-        }\r
-    }\r
-\r
-    if (alt_grouplist != grouplist) {\r
-        PyMem_Free(alt_grouplist);\r
-    }\r
-\r
-    return result;\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_INITGROUPS\r
-PyDoc_STRVAR(posix_initgroups__doc__,\r
-"initgroups(username, gid) -> None\n\n\\r
-Call the system initgroups() to initialize the group access list with all of\n\\r
-the groups of which the specified username is a member, plus the specified\n\\r
-group id.");\r
-\r
-static PyObject *\r
-posix_initgroups(PyObject *self, PyObject *args)\r
-{\r
-    char *username;\r
-    long gid;\r
-\r
-    if (!PyArg_ParseTuple(args, "sl:initgroups", &username, &gid))\r
-        return NULL;\r
-\r
-    if (initgroups(username, (gid_t) gid) == -1)\r
-        return PyErr_SetFromErrno(PyExc_OSError);\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_GETPGID\r
-PyDoc_STRVAR(posix_getpgid__doc__,\r
-"getpgid(pid) -> pgid\n\n\\r
-Call the system call getpgid().");\r
-\r
-static PyObject *\r
-posix_getpgid(PyObject *self, PyObject *args)\r
-{\r
-    pid_t pid, pgid;\r
-    if (!PyArg_ParseTuple(args, PARSE_PID ":getpgid", &pid))\r
-        return NULL;\r
-    pgid = getpgid(pid);\r
-    if (pgid < 0)\r
-        return posix_error();\r
-    return PyLong_FromPid(pgid);\r
-}\r
-#endif /* HAVE_GETPGID */\r
-\r
-\r
-#ifdef HAVE_GETPGRP\r
-PyDoc_STRVAR(posix_getpgrp__doc__,\r
-"getpgrp() -> pgrp\n\n\\r
-Return the current process group id.");\r
-\r
-static PyObject *\r
-posix_getpgrp(PyObject *self, PyObject *noargs)\r
-{\r
-#ifdef GETPGRP_HAVE_ARG\r
-    return PyLong_FromPid(getpgrp(0));\r
-#else /* GETPGRP_HAVE_ARG */\r
-    return PyLong_FromPid(getpgrp());\r
-#endif /* GETPGRP_HAVE_ARG */\r
-}\r
-#endif /* HAVE_GETPGRP */\r
-\r
-\r
-#ifdef HAVE_SETPGRP\r
-PyDoc_STRVAR(posix_setpgrp__doc__,\r
-"setpgrp()\n\n\\r
-Make this process the process group leader.");\r
-\r
-static PyObject *\r
-posix_setpgrp(PyObject *self, PyObject *noargs)\r
-{\r
-#ifdef SETPGRP_HAVE_ARG\r
-    if (setpgrp(0, 0) < 0)\r
-#else /* SETPGRP_HAVE_ARG */\r
-    if (setpgrp() < 0)\r
-#endif /* SETPGRP_HAVE_ARG */\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-#endif /* HAVE_SETPGRP */\r
-\r
-#ifdef HAVE_GETPPID\r
-PyDoc_STRVAR(posix_getppid__doc__,\r
-"getppid() -> ppid\n\n\\r
-Return the parent's process id.");\r
-\r
-static PyObject *\r
-posix_getppid(PyObject *self, PyObject *noargs)\r
-{\r
-    return PyLong_FromPid(getppid());\r
-}\r
-#endif\r
-\r
-\r
 #ifdef HAVE_GETLOGIN\r
 PyDoc_STRVAR(posix_getlogin__doc__,\r
 "getlogin() -> string\n\n\\r
 #ifdef HAVE_GETLOGIN\r
 PyDoc_STRVAR(posix_getlogin__doc__,\r
 "getlogin() -> string\n\n\\r
@@ -2542,18 +2277,6 @@ posix_getlogin(PyObject *self, PyObject *noargs)
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifndef UEFI_C_SOURCE\r
-PyDoc_STRVAR(posix_getuid__doc__,\r
-"getuid() -> uid\n\n\\r
-Return the current process's user id.");\r
-\r
-static PyObject *\r
-posix_getuid(PyObject *self, PyObject *noargs)\r
-{\r
-    return PyInt_FromLong((long)getuid());\r
-}\r
-#endif  /* UEFI_C_SOURCE */\r
-\r
 #ifdef HAVE_KILL\r
 PyDoc_STRVAR(posix_kill__doc__,\r
 "kill(pid, sig)\n\n\\r
 #ifdef HAVE_KILL\r
 PyDoc_STRVAR(posix_kill__doc__,\r
 "kill(pid, sig)\n\n\\r
@@ -2588,29 +2311,6 @@ posix_kill(PyObject *self, PyObject *args)
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifdef HAVE_KILLPG\r
-PyDoc_STRVAR(posix_killpg__doc__,\r
-"killpg(pgid, sig)\n\n\\r
-Kill a process group with a signal.");\r
-\r
-static PyObject *\r
-posix_killpg(PyObject *self, PyObject *args)\r
-{\r
-    int sig;\r
-    pid_t pgid;\r
-    /* XXX some man pages make the `pgid` parameter an int, others\r
-       a pid_t. Since getpgrp() returns a pid_t, we assume killpg should\r
-       take the same type. Moreover, pid_t is always at least as wide as\r
-       int (else compilation of this module fails), which is safe. */\r
-    if (!PyArg_ParseTuple(args, PARSE_PID "i:killpg", &pgid, &sig))\r
-        return NULL;\r
-    if (killpg(pgid, sig) == -1)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif\r
-\r
 #ifdef HAVE_PLOCK\r
 \r
 #ifdef HAVE_SYS_LOCK_H\r
 #ifdef HAVE_PLOCK\r
 \r
 #ifdef HAVE_SYS_LOCK_H\r
@@ -2640,116 +2340,6 @@ PyDoc_STRVAR(posix_popen__doc__,
 "popen(command [, mode='r' [, bufsize]]) -> pipe\n\n\\r
 Open a pipe to/from a command returning a file object.");\r
 \r
 "popen(command [, mode='r' [, bufsize]]) -> pipe\n\n\\r
 Open a pipe to/from a command returning a file object.");\r
 \r
-#if defined(PYOS_OS2)\r
-#if defined(PYCC_VACPP)\r
-static int\r
-async_system(const char *command)\r
-{\r
-    char errormsg[256], args[1024];\r
-    RESULTCODES rcodes;\r
-    APIRET rc;\r
-\r
-    char *shell = getenv("COMSPEC");\r
-    if (!shell)\r
-        shell = "cmd";\r
-\r
-    /* avoid overflowing the argument buffer */\r
-    if (strlen(shell) + 3 + strlen(command) >= 1024)\r
-        return ERROR_NOT_ENOUGH_MEMORY\r
-\r
-    args[0] = '\0';\r
-    strcat(args, shell);\r
-    strcat(args, "/c ");\r
-    strcat(args, command);\r
-\r
-    /* execute asynchronously, inheriting the environment */\r
-    rc = DosExecPgm(errormsg,\r
-                    sizeof(errormsg),\r
-                    EXEC_ASYNC,\r
-                    args,\r
-                    NULL,\r
-                    &rcodes,\r
-                    shell);\r
-    return rc;\r
-}\r
-\r
-static FILE *\r
-popen(const char *command, const char *mode, int pipesize, int *err)\r
-{\r
-    int oldfd, tgtfd;\r
-    HFILE pipeh[2];\r
-    APIRET rc;\r
-\r
-    /* mode determines which of stdin or stdout is reconnected to\r
-     * the pipe to the child\r
-     */\r
-    if (strchr(mode, 'r') != NULL) {\r
-        tgt_fd = 1;             /* stdout */\r
-    } else if (strchr(mode, 'w')) {\r
-        tgt_fd = 0;             /* stdin */\r
-    } else {\r
-        *err = ERROR_INVALID_ACCESS;\r
-        return NULL;\r
-    }\r
-\r
-    /* setup the pipe */\r
-    if ((rc = DosCreatePipe(&pipeh[0], &pipeh[1], pipesize)) != NO_ERROR) {\r
-        *err = rc;\r
-        return NULL;\r
-    }\r
-\r
-    /* prevent other threads accessing stdio */\r
-    DosEnterCritSec();\r
-\r
-    /* reconnect stdio and execute child */\r
-    oldfd = dup(tgtfd);\r
-    close(tgtfd);\r
-    if (dup2(pipeh[tgtfd], tgtfd) == 0) {\r
-        DosClose(pipeh[tgtfd]);\r
-        rc = async_system(command);\r
-    }\r
-\r
-    /* restore stdio */\r
-    dup2(oldfd, tgtfd);\r
-    close(oldfd);\r
-\r
-    /* allow other threads access to stdio */\r
-    DosExitCritSec();\r
-\r
-    /* if execution of child was successful return file stream */\r
-    if (rc == NO_ERROR)\r
-        return fdopen(pipeh[1 - tgtfd], mode);\r
-    else {\r
-        DosClose(pipeh[1 - tgtfd]);\r
-        *err = rc;\r
-        return NULL;\r
-    }\r
-}\r
-\r
-static PyObject *\r
-posix_popen(PyObject *self, PyObject *args)\r
-{\r
-    char *name;\r
-    char *mode = "r";\r
-    int   err, bufsize = -1;\r
-    FILE *fp;\r
-    PyObject *f;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    fp = popen(name, mode, (bufsize > 0) ? bufsize : 4096, &err);\r
-    Py_END_ALLOW_THREADS\r
-    if (fp == NULL)\r
-        return os2_error(err);\r
-\r
-    f = PyFile_FromFile(fp, name, mode, fclose);\r
-    if (f != NULL)\r
-        PyFile_SetBufSize(f, bufsize);\r
-    return f;\r
-}\r
-\r
-#elif defined(PYCC_GCC)\r
-\r
 /* standard posix version of popen() support */\r
 static PyObject *\r
 posix_popen(PyObject *self, PyObject *args)\r
 /* standard posix version of popen() support */\r
 static PyObject *\r
 posix_popen(PyObject *self, PyObject *args)\r
@@ -2761,6 +2351,11 @@ posix_popen(PyObject *self, PyObject *args)
     PyObject *f;\r
     if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))\r
         return NULL;\r
     PyObject *f;\r
     if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))\r
         return NULL;\r
+    /* Strip mode of binary or text modifiers */\r
+    if (strcmp(mode, "rb") == 0 || strcmp(mode, "rt") == 0)\r
+        mode = "r";\r
+    else if (strcmp(mode, "wb") == 0 || strcmp(mode, "wt") == 0)\r
+        mode = "w";\r
     Py_BEGIN_ALLOW_THREADS\r
     fp = popen(name, mode);\r
     Py_END_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
     fp = popen(name, mode);\r
     Py_END_ALLOW_THREADS\r
@@ -2772,4033 +2367,1334 @@ posix_popen(PyObject *self, PyObject *args)
     return f;\r
 }\r
 \r
     return f;\r
 }\r
 \r
-/* fork() under OS/2 has lots'o'warts\r
- * EMX supports pipe() and spawn*() so we can synthesize popen[234]()\r
- * most of this code is a ripoff of the win32 code, but using the\r
- * capabilities of EMX's C library routines\r
- */\r
-\r
-/* These tell _PyPopen() whether to return 1, 2, or 3 file objects. */\r
-#define POPEN_1 1\r
-#define POPEN_2 2\r
-#define POPEN_3 3\r
-#define POPEN_4 4\r
-\r
-static PyObject *_PyPopen(char *, int, int, int);\r
-static int _PyPclose(FILE *file);\r
-\r
-/*\r
- * Internal dictionary mapping popen* file pointers to process handles,\r
- * for use when retrieving the process exit code.  See _PyPclose() below\r
- * for more information on this dictionary's use.\r
- */\r
-static PyObject *_PyPopenProcs = NULL;\r
-\r
-/* os2emx version of popen2()\r
- *\r
- * The result of this function is a pipe (file) connected to the\r
- * process's stdin, and a pipe connected to the process's stdout.\r
- */\r
+#endif /* HAVE_POPEN */\r
 \r
 \r
+#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)\r
 static PyObject *\r
 static PyObject *\r
-os2emx_popen2(PyObject *self, PyObject  *args)\r
+wait_helper(pid_t pid, int status, struct rusage *ru)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm=0;\r
+    PyObject *result;\r
+    static PyObject *struct_rusage;\r
 \r
 \r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen2", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
+    if (pid == -1)\r
+        return posix_error();\r
+\r
+    if (struct_rusage == NULL) {\r
+        PyObject *m = PyImport_ImportModuleNoBlock("resource");\r
+        if (m == NULL)\r
+            return NULL;\r
+        struct_rusage = PyObject_GetAttrString(m, "struct_rusage");\r
+        Py_DECREF(m);\r
+        if (struct_rusage == NULL)\r
+            return NULL;\r
+    }\r
 \r
 \r
-    if (*mode == 't')\r
-        tm = O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");\r
+    /* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */\r
+    result = PyStructSequence_New((PyTypeObject*) struct_rusage);\r
+    if (!result)\r
         return NULL;\r
         return NULL;\r
-    } else\r
-        tm = O_BINARY;\r
 \r
 \r
-    f = _PyPopen(cmdstring, tm, POPEN_2, bufsize);\r
+#ifndef doubletime\r
+#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)\r
+#endif\r
 \r
 \r
-    return f;\r
+    PyStructSequence_SET_ITEM(result, 0,\r
+                              PyFloat_FromDouble(doubletime(ru->ru_utime)));\r
+    PyStructSequence_SET_ITEM(result, 1,\r
+                              PyFloat_FromDouble(doubletime(ru->ru_stime)));\r
+#define SET_INT(result, index, value)\\r
+        PyStructSequence_SET_ITEM(result, index, PyInt_FromLong(value))\r
+    SET_INT(result, 2, ru->ru_maxrss);\r
+    SET_INT(result, 3, ru->ru_ixrss);\r
+    SET_INT(result, 4, ru->ru_idrss);\r
+    SET_INT(result, 5, ru->ru_isrss);\r
+    SET_INT(result, 6, ru->ru_minflt);\r
+    SET_INT(result, 7, ru->ru_majflt);\r
+    SET_INT(result, 8, ru->ru_nswap);\r
+    SET_INT(result, 9, ru->ru_inblock);\r
+    SET_INT(result, 10, ru->ru_oublock);\r
+    SET_INT(result, 11, ru->ru_msgsnd);\r
+    SET_INT(result, 12, ru->ru_msgrcv);\r
+    SET_INT(result, 13, ru->ru_nsignals);\r
+    SET_INT(result, 14, ru->ru_nvcsw);\r
+    SET_INT(result, 15, ru->ru_nivcsw);\r
+#undef SET_INT\r
+\r
+    if (PyErr_Occurred()) {\r
+        Py_DECREF(result);\r
+        return NULL;\r
+    }\r
+\r
+    return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);\r
 }\r
 }\r
+#endif /* HAVE_WAIT3 || HAVE_WAIT4 */\r
 \r
 \r
-/*\r
- * Variation on os2emx.popen2\r
- *\r
- * The result of this function is 3 pipes - the process's stdin,\r
- * stdout and stderr\r
- */\r
+#ifdef HAVE_WAIT3\r
+PyDoc_STRVAR(posix_wait3__doc__,\r
+"wait3(options) -> (pid, status, rusage)\n\n\\r
+Wait for completion of a child process.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-os2emx_popen3(PyObject *self, PyObject *args)\r
+posix_wait3(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm = 0;\r
+    pid_t pid;\r
+    int options;\r
+    struct rusage ru;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen3", &cmdstring, &mode, &bufsize))\r
+    if (!PyArg_ParseTuple(args, "i:wait3", &options))\r
         return NULL;\r
 \r
         return NULL;\r
 \r
-    if (*mode == 't')\r
-        tm = O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");\r
-        return NULL;\r
-    } else\r
-        tm = O_BINARY;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    pid = wait3(&status, options, &ru);\r
+    Py_END_ALLOW_THREADS\r
 \r
 \r
-    f = _PyPopen(cmdstring, tm, POPEN_3, bufsize);\r
-\r
-    return f;\r
+    return wait_helper(pid, WAIT_STATUS_INT(status), &ru);\r
 }\r
 }\r
+#endif /* HAVE_WAIT3 */\r
 \r
 \r
-/*\r
- * Variation on os2emx.popen2\r
- *\r
- * The result of this function is 2 pipes - the processes stdin,\r
- * and stdout+stderr combined as a single pipe.\r
- */\r
+#ifdef HAVE_WAIT4\r
+PyDoc_STRVAR(posix_wait4__doc__,\r
+"wait4(pid, options) -> (pid, status, rusage)\n\n\\r
+Wait for completion of a given child process.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-os2emx_popen4(PyObject *self, PyObject  *args)\r
+posix_wait4(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm = 0;\r
-\r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen4", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
+    pid_t pid;\r
+    int options;\r
+    struct rusage ru;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    if (*mode == 't')\r
-        tm = O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");\r
+    if (!PyArg_ParseTuple(args, PARSE_PID "i:wait4", &pid, &options))\r
         return NULL;\r
         return NULL;\r
-    } else\r
-        tm = O_BINARY;\r
 \r
 \r
-    f = _PyPopen(cmdstring, tm, POPEN_4, bufsize);\r
+    Py_BEGIN_ALLOW_THREADS\r
+    pid = wait4(pid, &status, options, &ru);\r
+    Py_END_ALLOW_THREADS\r
 \r
 \r
-    return f;\r
+    return wait_helper(pid, WAIT_STATUS_INT(status), &ru);\r
 }\r
 }\r
+#endif /* HAVE_WAIT4 */\r
 \r
 \r
-/* a couple of structures for convenient handling of multiple\r
- * file handles and pipes\r
- */\r
-struct file_ref\r
-{\r
-    int handle;\r
-    int flags;\r
-};\r
-\r
-struct pipe_ref\r
-{\r
-    int rd;\r
-    int wr;\r
-};\r
-\r
-/* The following code is derived from the win32 code */\r
+#ifdef HAVE_WAITPID\r
+PyDoc_STRVAR(posix_waitpid__doc__,\r
+"waitpid(pid, options) -> (pid, status)\n\n\\r
+Wait for completion of a given child process.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-_PyPopen(char *cmdstring, int mode, int n, int bufsize)\r
+posix_waitpid(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    struct file_ref stdio[3];\r
-    struct pipe_ref p_fd[3];\r
-    FILE *p_s[3];\r
-    int file_count, i, pipe_err;\r
-    pid_t pipe_pid;\r
-    char *shell, *sh_name, *opt, *rd_mode, *wr_mode;\r
-    PyObject *f, *p_f[3];\r
-\r
-    /* file modes for subsequent fdopen's on pipe handles */\r
-    if (mode == O_TEXT)\r
-    {\r
-        rd_mode = "rt";\r
-        wr_mode = "wt";\r
-    }\r
-    else\r
-    {\r
-        rd_mode = "rb";\r
-        wr_mode = "wb";\r
-    }\r
-\r
-    /* prepare shell references */\r
-    if ((shell = getenv("EMXSHELL")) == NULL)\r
-        if ((shell = getenv("COMSPEC")) == NULL)\r
-        {\r
-            errno = ENOENT;\r
-            return posix_error();\r
-        }\r
-\r
-    sh_name = _getname(shell);\r
-    if (stricmp(sh_name, "cmd.exe") == 0 || stricmp(sh_name, "4os2.exe") == 0)\r
-        opt = "/c";\r
-    else\r
-        opt = "-c";\r
-\r
-    /* save current stdio fds + their flags, and set not inheritable */\r
-    i = pipe_err = 0;\r
-    while (pipe_err >= 0 && i < 3)\r
-    {\r
-        pipe_err = stdio[i].handle = dup(i);\r
-        stdio[i].flags = fcntl(i, F_GETFD, 0);\r
-        fcntl(stdio[i].handle, F_SETFD, stdio[i].flags | FD_CLOEXEC);\r
-        i++;\r
-    }\r
-    if (pipe_err < 0)\r
-    {\r
-        /* didn't get them all saved - clean up and bail out */\r
-        int saved_err = errno;\r
-        while (i-- > 0)\r
-        {\r
-            close(stdio[i].handle);\r
-        }\r
-        errno = saved_err;\r
-        return posix_error();\r
-    }\r
+    pid_t pid;\r
+    int options;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    /* create pipe ends */\r
-    file_count = 2;\r
-    if (n == POPEN_3)\r
-        file_count = 3;\r
-    i = pipe_err = 0;\r
-    while ((pipe_err == 0) && (i < file_count))\r
-        pipe_err = pipe((int *)&p_fd[i++]);\r
-    if (pipe_err < 0)\r
-    {\r
-        /* didn't get them all made - clean up and bail out */\r
-        while (i-- > 0)\r
-        {\r
-            close(p_fd[i].wr);\r
-            close(p_fd[i].rd);\r
-        }\r
-        errno = EPIPE;\r
+    if (!PyArg_ParseTuple(args, PARSE_PID "i:waitpid", &pid, &options))\r
+        return NULL;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    pid = waitpid(pid, &status, options);\r
+    Py_END_ALLOW_THREADS\r
+    if (pid == -1)\r
         return posix_error();\r
         return posix_error();\r
-    }\r
-\r
-    /* change the actual standard IO streams over temporarily,\r
-     * making the retained pipe ends non-inheritable\r
-     */\r
-    pipe_err = 0;\r
 \r
 \r
-    /* - stdin */\r
-    if (dup2(p_fd[0].rd, 0) == 0)\r
-    {\r
-        close(p_fd[0].rd);\r
-        i = fcntl(p_fd[0].wr, F_GETFD, 0);\r
-        fcntl(p_fd[0].wr, F_SETFD, i | FD_CLOEXEC);\r
-        if ((p_s[0] = fdopen(p_fd[0].wr, wr_mode)) == NULL)\r
-        {\r
-            close(p_fd[0].wr);\r
-            pipe_err = -1;\r
-        }\r
-    }\r
-    else\r
-    {\r
-        pipe_err = -1;\r
-    }\r
+    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));\r
+}\r
 \r
 \r
-    /* - stdout */\r
-    if (pipe_err == 0)\r
-    {\r
-        if (dup2(p_fd[1].wr, 1) == 1)\r
-        {\r
-            close(p_fd[1].wr);\r
-            i = fcntl(p_fd[1].rd, F_GETFD, 0);\r
-            fcntl(p_fd[1].rd, F_SETFD, i | FD_CLOEXEC);\r
-            if ((p_s[1] = fdopen(p_fd[1].rd, rd_mode)) == NULL)\r
-            {\r
-                close(p_fd[1].rd);\r
-                pipe_err = -1;\r
-            }\r
-        }\r
-        else\r
-        {\r
-            pipe_err = -1;\r
-        }\r
-    }\r
+#elif defined(HAVE_CWAIT)\r
 \r
 \r
-    /* - stderr, as required */\r
-    if (pipe_err == 0)\r
-        switch (n)\r
-        {\r
-            case POPEN_3:\r
-            {\r
-                if (dup2(p_fd[2].wr, 2) == 2)\r
-                {\r
-                    close(p_fd[2].wr);\r
-                    i = fcntl(p_fd[2].rd, F_GETFD, 0);\r
-                    fcntl(p_fd[2].rd, F_SETFD, i | FD_CLOEXEC);\r
-                    if ((p_s[2] = fdopen(p_fd[2].rd, rd_mode)) == NULL)\r
-                    {\r
-                        close(p_fd[2].rd);\r
-                        pipe_err = -1;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    pipe_err = -1;\r
-                }\r
-                break;\r
-            }\r
+/* MS C has a variant of waitpid() that's usable for most purposes. */\r
+PyDoc_STRVAR(posix_waitpid__doc__,\r
+"waitpid(pid, options) -> (pid, status << 8)\n\n"\r
+"Wait for completion of a given process.  options is ignored on Windows.");\r
 \r
 \r
-            case POPEN_4:\r
-            {\r
-                if (dup2(1, 2) != 2)\r
-                {\r
-                    pipe_err = -1;\r
-                }\r
-                break;\r
-            }\r
-        }\r
+static PyObject *\r
+posix_waitpid(PyObject *self, PyObject *args)\r
+{\r
+    Py_intptr_t pid;\r
+    int status, options;\r
 \r
 \r
-    /* spawn the child process */\r
-    if (pipe_err == 0)\r
-    {\r
-        pipe_pid = spawnlp(P_NOWAIT, shell, shell, opt, cmdstring, (char *)0);\r
-        if (pipe_pid == -1)\r
-        {\r
-            pipe_err = -1;\r
-        }\r
-        else\r
-        {\r
-            /* save the PID into the FILE structure\r
-             * NOTE: this implementation doesn't actually\r
-             * take advantage of this, but do it for\r
-             * completeness - AIM Apr01\r
-             */\r
-            for (i = 0; i < file_count; i++)\r
-                p_s[i]->_pid = pipe_pid;\r
-        }\r
-    }\r
+    if (!PyArg_ParseTuple(args, PARSE_PID "i:waitpid", &pid, &options))\r
+        return NULL;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    pid = _cwait(&status, pid, options);\r
+    Py_END_ALLOW_THREADS\r
+    if (pid == -1)\r
+        return posix_error();\r
 \r
 \r
-    /* reset standard IO to normal */\r
-    for (i = 0; i < 3; i++)\r
-    {\r
-        dup2(stdio[i].handle, i);\r
-        fcntl(i, F_SETFD, stdio[i].flags);\r
-        close(stdio[i].handle);\r
-    }\r
+    /* shift the status left a byte so this is more like the POSIX waitpid */\r
+    return Py_BuildValue("Ni", PyLong_FromPid(pid), status << 8);\r
+}\r
+#endif /* HAVE_WAITPID || HAVE_CWAIT */\r
 \r
 \r
-    /* if any remnant problems, clean up and bail out */\r
-    if (pipe_err < 0)\r
-    {\r
-        for (i = 0; i < 3; i++)\r
-        {\r
-            close(p_fd[i].rd);\r
-            close(p_fd[i].wr);\r
-        }\r
-        errno = EPIPE;\r
-        return posix_error_with_filename(cmdstring);\r
-    }\r
+#ifdef HAVE_WAIT\r
+PyDoc_STRVAR(posix_wait__doc__,\r
+"wait() -> (pid, status)\n\n\\r
+Wait for completion of a child process.");\r
 \r
 \r
-    /* build tuple of file objects to return */\r
-    if ((p_f[0] = PyFile_FromFile(p_s[0], cmdstring, wr_mode, _PyPclose)) != NULL)\r
-        PyFile_SetBufSize(p_f[0], bufsize);\r
-    if ((p_f[1] = PyFile_FromFile(p_s[1], cmdstring, rd_mode, _PyPclose)) != NULL)\r
-        PyFile_SetBufSize(p_f[1], bufsize);\r
-    if (n == POPEN_3)\r
-    {\r
-        if ((p_f[2] = PyFile_FromFile(p_s[2], cmdstring, rd_mode, _PyPclose)) != NULL)\r
-            PyFile_SetBufSize(p_f[0], bufsize);\r
-        f = PyTuple_Pack(3, p_f[0], p_f[1], p_f[2]);\r
-    }\r
-    else\r
-        f = PyTuple_Pack(2, p_f[0], p_f[1]);\r
-\r
-    /*\r
-     * Insert the files we've created into the process dictionary\r
-     * all referencing the list with the process handle and the\r
-     * initial number of files (see description below in _PyPclose).\r
-     * Since if _PyPclose later tried to wait on a process when all\r
-     * handles weren't closed, it could create a deadlock with the\r
-     * child, we spend some energy here to try to ensure that we\r
-     * either insert all file handles into the dictionary or none\r
-     * at all.  It's a little clumsy with the various popen modes\r
-     * and variable number of files involved.\r
-     */\r
-    if (!_PyPopenProcs)\r
-    {\r
-        _PyPopenProcs = PyDict_New();\r
-    }\r
+static PyObject *\r
+posix_wait(PyObject *self, PyObject *noargs)\r
+{\r
+    pid_t pid;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    if (_PyPopenProcs)\r
-    {\r
-        PyObject *procObj, *pidObj, *intObj, *fileObj[3];\r
-        int ins_rc[3];\r
+    Py_BEGIN_ALLOW_THREADS\r
+    pid = wait(&status);\r
+    Py_END_ALLOW_THREADS\r
+    if (pid == -1)\r
+        return posix_error();\r
 \r
 \r
-        fileObj[0] = fileObj[1] = fileObj[2] = NULL;\r
-        ins_rc[0]  = ins_rc[1]  = ins_rc[2]  = 0;\r
+    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));\r
+}\r
+#endif\r
 \r
 \r
-        procObj = PyList_New(2);\r
-        pidObj = PyLong_FromPid(pipe_pid);\r
-        intObj = PyInt_FromLong((long) file_count);\r
 \r
 \r
-        if (procObj && pidObj && intObj)\r
-        {\r
-            PyList_SetItem(procObj, 0, pidObj);\r
-            PyList_SetItem(procObj, 1, intObj);\r
-\r
-            fileObj[0] = PyLong_FromVoidPtr(p_s[0]);\r
-            if (fileObj[0])\r
-            {\r
-                ins_rc[0] = PyDict_SetItem(_PyPopenProcs,\r
-                                           fileObj[0],\r
-                                           procObj);\r
-            }\r
-            fileObj[1] = PyLong_FromVoidPtr(p_s[1]);\r
-            if (fileObj[1])\r
-            {\r
-                ins_rc[1] = PyDict_SetItem(_PyPopenProcs,\r
-                                           fileObj[1],\r
-                                           procObj);\r
-            }\r
-            if (file_count >= 3)\r
-            {\r
-                fileObj[2] = PyLong_FromVoidPtr(p_s[2]);\r
-                if (fileObj[2])\r
-                {\r
-                    ins_rc[2] = PyDict_SetItem(_PyPopenProcs,\r
-                                               fileObj[2],\r
-                                               procObj);\r
-                }\r
-            }\r
+PyDoc_STRVAR(posix_lstat__doc__,\r
+"lstat(path) -> stat result\n\n\\r
+Like stat(path), but do not follow symbolic links.");\r
 \r
 \r
-            if (ins_rc[0] < 0 || !fileObj[0] ||\r
-                ins_rc[1] < 0 || (file_count > 1 && !fileObj[1]) ||\r
-                ins_rc[2] < 0 || (file_count > 2 && !fileObj[2]))\r
-            {\r
-                /* Something failed - remove any dictionary\r
-                 * entries that did make it.\r
-                 */\r
-                if (!ins_rc[0] && fileObj[0])\r
-                {\r
-                    PyDict_DelItem(_PyPopenProcs,\r
-                                   fileObj[0]);\r
-                }\r
-                if (!ins_rc[1] && fileObj[1])\r
-                {\r
-                    PyDict_DelItem(_PyPopenProcs,\r
-                                   fileObj[1]);\r
-                }\r
-                if (!ins_rc[2] && fileObj[2])\r
-                {\r
-                    PyDict_DelItem(_PyPopenProcs,\r
-                                   fileObj[2]);\r
-                }\r
-            }\r
-        }\r
+static PyObject *\r
+posix_lstat(PyObject *self, PyObject *args)\r
+{\r
+#ifdef HAVE_LSTAT\r
+    return posix_do_stat(self, args, "et:lstat", lstat, NULL, NULL);\r
+#else /* !HAVE_LSTAT */\r
+    return posix_do_stat(self, args, "et:lstat", STAT, NULL, NULL);\r
+#endif /* !HAVE_LSTAT */\r
+}\r
 \r
 \r
-        /*\r
-         * Clean up our localized references for the dictionary keys\r
-         * and value since PyDict_SetItem will Py_INCREF any copies\r
-         * that got placed in the dictionary.\r
-         */\r
-        Py_XDECREF(procObj);\r
-        Py_XDECREF(fileObj[0]);\r
-        Py_XDECREF(fileObj[1]);\r
-        Py_XDECREF(fileObj[2]);\r
-    }\r
 \r
 \r
-    /* Child is launched. */\r
-    return f;\r
-}\r
+#ifdef HAVE_READLINK\r
+PyDoc_STRVAR(posix_readlink__doc__,\r
+"readlink(path) -> path\n\n\\r
+Return a string representing the path to which the symbolic link points.");\r
 \r
 \r
-/*\r
- * Wrapper for fclose() to use for popen* files, so we can retrieve the\r
- * exit code for the child process and return as a result of the close.\r
- *\r
- * This function uses the _PyPopenProcs dictionary in order to map the\r
- * input file pointer to information about the process that was\r
- * originally created by the popen* call that created the file pointer.\r
- * The dictionary uses the file pointer as a key (with one entry\r
- * inserted for each file returned by the original popen* call) and a\r
- * single list object as the value for all files from a single call.\r
- * The list object contains the Win32 process handle at [0], and a file\r
- * count at [1], which is initialized to the total number of file\r
- * handles using that list.\r
- *\r
- * This function closes whichever handle it is passed, and decrements\r
- * the file count in the dictionary for the process handle pointed to\r
- * by this file.  On the last close (when the file count reaches zero),\r
- * this function will wait for the child process and then return its\r
- * exit code as the result of the close() operation.  This permits the\r
- * files to be closed in any order - it is always the close() of the\r
- * final handle that will return the exit code.\r
- *\r
- * NOTE: This function is currently called with the GIL released.\r
- * hence we use the GILState API to manage our state.\r
- */\r
-\r
-static int _PyPclose(FILE *file)\r
+static PyObject *\r
+posix_readlink(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int result;\r
-    int exit_code;\r
-    pid_t pipe_pid;\r
-    PyObject *procObj, *pidObj, *intObj, *fileObj;\r
-    int file_count;\r
-#ifdef WITH_THREAD\r
-    PyGILState_STATE state;\r
+    PyObject* v;\r
+    char buf[MAXPATHLEN];\r
+    char *path;\r
+    int n;\r
+#ifdef Py_USING_UNICODE\r
+    int arg_is_unicode = 0;\r
 #endif\r
 \r
 #endif\r
 \r
-    /* Close the file handle first, to ensure it can't block the\r
-     * child from exiting if it's the last handle.\r
-     */\r
-    result = fclose(file);\r
+    if (!PyArg_ParseTuple(args, "et:readlink",\r
+                          Py_FileSystemDefaultEncoding, &path))\r
+        return NULL;\r
+#ifdef Py_USING_UNICODE\r
+    v = PySequence_GetItem(args, 0);\r
+    if (v == NULL) {\r
+        PyMem_Free(path);\r
+        return NULL;\r
+    }\r
 \r
 \r
-#ifdef WITH_THREAD\r
-    state = PyGILState_Ensure();\r
+    if (PyUnicode_Check(v)) {\r
+        arg_is_unicode = 1;\r
+    }\r
+    Py_DECREF(v);\r
 #endif\r
 #endif\r
-    if (_PyPopenProcs)\r
-    {\r
-        if ((fileObj = PyLong_FromVoidPtr(file)) != NULL &&\r
-            (procObj = PyDict_GetItem(_PyPopenProcs,\r
-                                      fileObj)) != NULL &&\r
-            (pidObj = PyList_GetItem(procObj,0)) != NULL &&\r
-            (intObj = PyList_GetItem(procObj,1)) != NULL)\r
-        {\r
-            pipe_pid = (pid_t) PyLong_AsPid(pidObj);\r
-            file_count = (int) PyInt_AsLong(intObj);\r
-\r
-            if (file_count > 1)\r
-            {\r
-                /* Still other files referencing process */\r
-                file_count--;\r
-                PyList_SetItem(procObj,1,\r
-                               PyInt_FromLong((long) file_count));\r
-            }\r
-            else\r
-            {\r
-                /* Last file for this process */\r
-                if (result != EOF &&\r
-                    waitpid(pipe_pid, &exit_code, 0) == pipe_pid)\r
-                {\r
-                    /* extract exit status */\r
-                    if (WIFEXITED(exit_code))\r
-                    {\r
-                        result = WEXITSTATUS(exit_code);\r
-                    }\r
-                    else\r
-                    {\r
-                        errno = EPIPE;\r
-                        result = -1;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    /* Indicate failure - this will cause the file object\r
-                     * to raise an I/O error and translate the last\r
-                     * error code from errno.  We do have a problem with\r
-                     * last errors that overlap the normal errno table,\r
-                     * but that's a consistent problem with the file object.\r
-                     */\r
-                    result = -1;\r
-                }\r
-            }\r
 \r
 \r
-            /* Remove this file pointer from dictionary */\r
-            PyDict_DelItem(_PyPopenProcs, fileObj);\r
-\r
-            if (PyDict_Size(_PyPopenProcs) == 0)\r
-            {\r
-                Py_DECREF(_PyPopenProcs);\r
-                _PyPopenProcs = NULL;\r
-            }\r
-\r
-        } /* if object retrieval ok */\r
+    Py_BEGIN_ALLOW_THREADS\r
+    n = readlink(path, buf, (int) sizeof buf);\r
+    Py_END_ALLOW_THREADS\r
+    if (n < 0)\r
+        return posix_error_with_allocated_filename(path);\r
 \r
 \r
-        Py_XDECREF(fileObj);\r
-    } /* if _PyPopenProcs */\r
+    PyMem_Free(path);\r
+    v = PyString_FromStringAndSize(buf, n);\r
+#ifdef Py_USING_UNICODE\r
+    if (arg_is_unicode) {\r
+        PyObject *w;\r
 \r
 \r
-#ifdef WITH_THREAD\r
-    PyGILState_Release(state);\r
+        w = PyUnicode_FromEncodedObject(v,\r
+                                        Py_FileSystemDefaultEncoding,\r
+                                        "strict");\r
+        if (w != NULL) {\r
+            Py_DECREF(v);\r
+            v = w;\r
+        }\r
+        else {\r
+            /* fall back to the original byte string, as\r
+               discussed in patch #683592 */\r
+            PyErr_Clear();\r
+        }\r
+    }\r
 #endif\r
 #endif\r
-    return result;\r
+    return v;\r
 }\r
 }\r
-\r
-#endif /* PYCC_??? */\r
-\r
-#elif defined(MS_WINDOWS)\r
-\r
-/*\r
- * Portable 'popen' replacement for Win32.\r
- *\r
- * Written by Bill Tutt <billtut@microsoft.com>.  Minor tweaks\r
- * and 2.0 integration by Fredrik Lundh <fredrik@pythonware.com>\r
- * Return code handling by David Bolen <db3l@fitlinxx.com>.\r
- */\r
-\r
-#include <malloc.h>\r
-#include <io.h>\r
-#include <fcntl.h>\r
-\r
-/* These tell _PyPopen() wether to return 1, 2, or 3 file objects. */\r
-#define POPEN_1 1\r
-#define POPEN_2 2\r
-#define POPEN_3 3\r
-#define POPEN_4 4\r
-\r
-static PyObject *_PyPopen(char *, int, int);\r
-static int _PyPclose(FILE *file);\r
-\r
-/*\r
- * Internal dictionary mapping popen* file pointers to process handles,\r
- * for use when retrieving the process exit code.  See _PyPclose() below\r
- * for more information on this dictionary's use.\r
- */\r
-static PyObject *_PyPopenProcs = NULL;\r
+#endif /* HAVE_READLINK */\r
 \r
 \r
 \r
 \r
-/* popen that works from a GUI.\r
- *\r
- * The result of this function is a pipe (file) connected to the\r
- * processes stdin or stdout, depending on the requested mode.\r
- */\r
+#ifdef HAVE_SYMLINK\r
+PyDoc_STRVAR(posix_symlink__doc__,\r
+"symlink(src, dst)\n\n\\r
+Create a symbolic link pointing to src named dst.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_popen(PyObject *self, PyObject *args)\r
+posix_symlink(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm = 0;\r
-\r
-    char *cmdstring;\r
-    char *mode = "r";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
+    return posix_2str(args, "etet:symlink", symlink);\r
+}\r
+#endif /* HAVE_SYMLINK */\r
 \r
 \r
-    if (*mode == 'r')\r
-        tm = _O_RDONLY;\r
-    else if (*mode != 'w') {\r
-        PyErr_SetString(PyExc_ValueError, "popen() arg 2 must be 'r' or 'w'");\r
-        return NULL;\r
-    } else\r
-        tm = _O_WRONLY;\r
-\r
-    if (bufsize != -1) {\r
-        PyErr_SetString(PyExc_ValueError, "popen() arg 3 must be -1");\r
-        return NULL;\r
-    }\r
-\r
-    if (*(mode+1) == 't')\r
-        f = _PyPopen(cmdstring, tm | _O_TEXT, POPEN_1);\r
-    else if (*(mode+1) == 'b')\r
-        f = _PyPopen(cmdstring, tm | _O_BINARY, POPEN_1);\r
-    else\r
-        f = _PyPopen(cmdstring, tm | _O_TEXT, POPEN_1);\r
-\r
-    return f;\r
-}\r
-\r
-/* Variation on win32pipe.popen\r
- *\r
- * The result of this function is a pipe (file) connected to the\r
- * process's stdin, and a pipe connected to the process's stdout.\r
- */\r
 \r
 \r
+#ifdef HAVE_TIMES\r
+#define NEED_TICKS_PER_SECOND\r
+static long ticks_per_second = -1;\r
 static PyObject *\r
 static PyObject *\r
-win32_popen2(PyObject *self, PyObject  *args)\r
+posix_times(PyObject *self, PyObject *noargs)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm=0;\r
-\r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen2", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
-\r
-    if (*mode == 't')\r
-        tm = _O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "popen2() arg 2 must be 't' or 'b'");\r
-        return NULL;\r
-    } else\r
-        tm = _O_BINARY;\r
+    struct tms t;\r
+    clock_t c;\r
+    errno = 0;\r
+    c = times(&t);\r
+    if (c == (clock_t) -1)\r
+        return posix_error();\r
+    return Py_BuildValue("ddddd",\r
+                         (double)t.tms_utime / ticks_per_second,\r
+                         (double)t.tms_stime / ticks_per_second,\r
+                         (double)t.tms_cutime / ticks_per_second,\r
+                         (double)t.tms_cstime / ticks_per_second,\r
+                         (double)c / ticks_per_second);\r
+}\r
+#endif /* HAVE_TIMES */\r
 \r
 \r
-    if (bufsize != -1) {\r
-        PyErr_SetString(PyExc_ValueError, "popen2() arg 3 must be -1");\r
-        return NULL;\r
-    }\r
 \r
 \r
-    f = _PyPopen(cmdstring, tm, POPEN_2);\r
+#ifdef HAVE_TIMES\r
+PyDoc_STRVAR(posix_times__doc__,\r
+"times() -> (utime, stime, cutime, cstime, elapsed_time)\n\n\\r
+Return a tuple of floating point numbers indicating process times.");\r
+#endif\r
 \r
 \r
-    return f;\r
-}\r
 \r
 \r
-/*\r
- * Variation on <om win32pipe.popen>\r
- *\r
- * The result of this function is 3 pipes - the process's stdin,\r
- * stdout and stderr\r
- */\r
+#ifdef HAVE_GETSID\r
+PyDoc_STRVAR(posix_getsid__doc__,\r
+"getsid(pid) -> sid\n\n\\r
+Call the system call getsid().");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-win32_popen3(PyObject *self, PyObject *args)\r
+posix_getsid(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm = 0;\r
-\r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen3", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
-\r
-    if (*mode == 't')\r
-        tm = _O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "popen3() arg 2 must be 't' or 'b'");\r
+    pid_t pid;\r
+    int sid;\r
+    if (!PyArg_ParseTuple(args, PARSE_PID ":getsid", &pid))\r
         return NULL;\r
         return NULL;\r
-    } else\r
-        tm = _O_BINARY;\r
+    sid = getsid(pid);\r
+    if (sid < 0)\r
+        return posix_error();\r
+    return PyInt_FromLong((long)sid);\r
+}\r
+#endif /* HAVE_GETSID */\r
 \r
 \r
-    if (bufsize != -1) {\r
-        PyErr_SetString(PyExc_ValueError, "popen3() arg 3 must be -1");\r
-        return NULL;\r
-    }\r
 \r
 \r
-    f = _PyPopen(cmdstring, tm, POPEN_3);\r
+#ifdef HAVE_SETSID\r
+PyDoc_STRVAR(posix_setsid__doc__,\r
+"setsid()\n\n\\r
+Call the system call setsid().");\r
 \r
 \r
-    return f;\r
+static PyObject *\r
+posix_setsid(PyObject *self, PyObject *noargs)\r
+{\r
+    if (setsid() < 0)\r
+        return posix_error();\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
 }\r
 }\r
+#endif /* HAVE_SETSID */\r
 \r
 \r
-/*\r
- * Variation on win32pipe.popen\r
- *\r
- * The result of this function is 2 pipes - the processes stdin,\r
- * and stdout+stderr combined as a single pipe.\r
- */\r
+#ifdef HAVE_SETPGID\r
+PyDoc_STRVAR(posix_setpgid__doc__,\r
+"setpgid(pid, pgrp)\n\n\\r
+Call the system call setpgid().");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-win32_popen4(PyObject *self, PyObject  *args)\r
+posix_setpgid(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *f;\r
-    int tm = 0;\r
-\r
-    char *cmdstring;\r
-    char *mode = "t";\r
-    int bufsize = -1;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen4", &cmdstring, &mode, &bufsize))\r
-        return NULL;\r
-\r
-    if (*mode == 't')\r
-        tm = _O_TEXT;\r
-    else if (*mode != 'b') {\r
-        PyErr_SetString(PyExc_ValueError, "popen4() arg 2 must be 't' or 'b'");\r
-        return NULL;\r
-    } else\r
-        tm = _O_BINARY;\r
-\r
-    if (bufsize != -1) {\r
-        PyErr_SetString(PyExc_ValueError, "popen4() arg 3 must be -1");\r
+    pid_t pid;\r
+    int pgrp;\r
+    if (!PyArg_ParseTuple(args, PARSE_PID "i:setpgid", &pid, &pgrp))\r
         return NULL;\r
         return NULL;\r
-    }\r
-\r
-    f = _PyPopen(cmdstring, tm, POPEN_4);\r
-\r
-    return f;\r
+    if (setpgid(pid, pgrp) < 0)\r
+        return posix_error();\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
 }\r
 }\r
+#endif /* HAVE_SETPGID */\r
 \r
 \r
-static BOOL\r
-_PyPopenCreateProcess(char *cmdstring,\r
-                      HANDLE hStdin,\r
-                      HANDLE hStdout,\r
-                      HANDLE hStderr,\r
-                      HANDLE *hProcess)\r
-{\r
-    PROCESS_INFORMATION piProcInfo;\r
-    STARTUPINFO siStartInfo;\r
-    DWORD dwProcessFlags = 0;  /* no NEW_CONSOLE by default for Ctrl+C handling */\r
-    char *s1,*s2, *s3 = " /c ";\r
-    const char *szConsoleSpawn = "w9xpopen.exe";\r
-    int i;\r
-    Py_ssize_t x;\r
-\r
-    if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {\r
-        char *comshell;\r
-\r
-        s1 = (char *)alloca(i);\r
-        if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))\r
-            /* x < i, so x fits into an integer */\r
-            return (int)x;\r
-\r
-        /* Explicitly check if we are using COMMAND.COM.  If we are\r
-         * then use the w9xpopen hack.\r
-         */\r
-        comshell = s1 + x;\r
-        while (comshell >= s1 && *comshell != '\\')\r
-            --comshell;\r
-        ++comshell;\r
-\r
-        if (GetVersion() < 0x80000000 &&\r
-            _stricmp(comshell, "command.com") != 0) {\r
-            /* NT/2000 and not using command.com. */\r
-            x = i + strlen(s3) + strlen(cmdstring) + 1;\r
-            s2 = (char *)alloca(x);\r
-            ZeroMemory(s2, x);\r
-            PyOS_snprintf(s2, x, "%s%s%s", s1, s3, cmdstring);\r
-        }\r
-        else {\r
-            /*\r
-             * Oh gag, we're on Win9x or using COMMAND.COM. Use\r
-             * the workaround listed in KB: Q150956\r
-             */\r
-            char modulepath[_MAX_PATH];\r
-            struct stat statinfo;\r
-            GetModuleFileName(NULL, modulepath, sizeof(modulepath));\r
-            for (x = i = 0; modulepath[i]; i++)\r
-                if (modulepath[i] == SEP)\r
-                    x = i+1;\r
-            modulepath[x] = '\0';\r
-            /* Create the full-name to w9xpopen, so we can test it exists */\r
-            strncat(modulepath,\r
-                    szConsoleSpawn,\r
-                    (sizeof(modulepath)/sizeof(modulepath[0]))\r
-                        -strlen(modulepath));\r
-            if (stat(modulepath, &statinfo) != 0) {\r
-                size_t mplen = sizeof(modulepath)/sizeof(modulepath[0]);\r
-                /* Eeek - file-not-found - possibly an embedding\r
-                   situation - see if we can locate it in sys.prefix\r
-                */\r
-                strncpy(modulepath,\r
-                        Py_GetExecPrefix(),\r
-                        mplen);\r
-                modulepath[mplen-1] = '\0';\r
-                if (modulepath[strlen(modulepath)-1] != '\\')\r
-                    strcat(modulepath, "\\");\r
-                strncat(modulepath,\r
-                        szConsoleSpawn,\r
-                        mplen-strlen(modulepath));\r
-                /* No where else to look - raise an easily identifiable\r
-                   error, rather than leaving Windows to report\r
-                   "file not found" - as the user is probably blissfully\r
-                   unaware this shim EXE is used, and it will confuse them.\r
-                   (well, it confused me for a while ;-)\r
-                */\r
-                if (stat(modulepath, &statinfo) != 0) {\r
-                    PyErr_Format(PyExc_RuntimeError,\r
-                                 "Can not locate '%s' which is needed "\r
-                                 "for popen to work with your shell "\r
-                                 "or platform.",\r
-                                 szConsoleSpawn);\r
-                    return FALSE;\r
-                }\r
-            }\r
-            x = i + strlen(s3) + strlen(cmdstring) + 1 +\r
-                strlen(modulepath) +\r
-                strlen(szConsoleSpawn) + 1;\r
-\r
-            s2 = (char *)alloca(x);\r
-            ZeroMemory(s2, x);\r
-            /* To maintain correct argument passing semantics,\r
-               we pass the command-line as it stands, and allow\r
-               quoting to be applied.  w9xpopen.exe will then\r
-               use its argv vector, and re-quote the necessary\r
-               args for the ultimate child process.\r
-            */\r
-            PyOS_snprintf(\r
-                s2, x,\r
-                "\"%s\" %s%s%s",\r
-                modulepath,\r
-                s1,\r
-                s3,\r
-                cmdstring);\r
-            /* Not passing CREATE_NEW_CONSOLE has been known to\r
-               cause random failures on win9x.  Specifically a\r
-               dialog:\r
-               "Your program accessed mem currently in use at xxx"\r
-               and a hopeful warning about the stability of your\r
-               system.\r
-               Cost is Ctrl+C won't kill children, but anyone\r
-               who cares can have a go!\r
-            */\r
-            dwProcessFlags |= CREATE_NEW_CONSOLE;\r
-        }\r
-    }\r
-\r
-    /* Could be an else here to try cmd.exe / command.com in the path\r
-       Now we'll just error out.. */\r
-    else {\r
-        PyErr_SetString(PyExc_RuntimeError,\r
-                        "Cannot locate a COMSPEC environment variable to "\r
-                        "use as the shell");\r
-        return FALSE;\r
-    }\r
-\r
-    ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));\r
-    siStartInfo.cb = sizeof(STARTUPINFO);\r
-    siStartInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;\r
-    siStartInfo.hStdInput = hStdin;\r
-    siStartInfo.hStdOutput = hStdout;\r
-    siStartInfo.hStdError = hStderr;\r
-    siStartInfo.wShowWindow = SW_HIDE;\r
-\r
-    if (CreateProcess(NULL,\r
-                      s2,\r
-                      NULL,\r
-                      NULL,\r
-                      TRUE,\r
-                      dwProcessFlags,\r
-                      NULL,\r
-                      NULL,\r
-                      &siStartInfo,\r
-                      &piProcInfo) ) {\r
-        /* Close the handles now so anyone waiting is woken. */\r
-        CloseHandle(piProcInfo.hThread);\r
-\r
-        /* Return process handle */\r
-        *hProcess = piProcInfo.hProcess;\r
-        return TRUE;\r
-    }\r
-    win32_error("CreateProcess", s2);\r
-    return FALSE;\r
-}\r
 \r
 \r
-/* The following code is based off of KB: Q190351 */\r
+#ifdef HAVE_TCGETPGRP\r
+PyDoc_STRVAR(posix_tcgetpgrp__doc__,\r
+"tcgetpgrp(fd) -> pgid\n\n\\r
+Return the process group associated with the terminal given by a fd.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-_PyPopen(char *cmdstring, int mode, int n)\r
+posix_tcgetpgrp(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr,\r
-        hChildStderrRd, hChildStderrWr, hChildStdinWrDup, hChildStdoutRdDup,\r
-        hChildStderrRdDup, hProcess; /* hChildStdoutWrDup; */\r
-\r
-    SECURITY_ATTRIBUTES saAttr;\r
-    BOOL fSuccess;\r
-    int fd1, fd2, fd3;\r
-    FILE *f1, *f2, *f3;\r
-    long file_count;\r
-    PyObject *f;\r
-\r
-    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);\r
-    saAttr.bInheritHandle = TRUE;\r
-    saAttr.lpSecurityDescriptor = NULL;\r
-\r
-    if (!CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))\r
-        return win32_error("CreatePipe", NULL);\r
-\r
-    /* Create new output read handle and the input write handle. Set\r
-     * the inheritance properties to FALSE. Otherwise, the child inherits\r
-     * these handles; resulting in non-closeable handles to the pipes\r
-     * being created. */\r
-     fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,\r
-                                GetCurrentProcess(), &hChildStdinWrDup, 0,\r
-                                FALSE,\r
-                                DUPLICATE_SAME_ACCESS);\r
-     if (!fSuccess)\r
-         return win32_error("DuplicateHandle", NULL);\r
-\r
-     /* Close the inheritable version of ChildStdin\r
-    that we're using. */\r
-     CloseHandle(hChildStdinWr);\r
-\r
-     if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))\r
-         return win32_error("CreatePipe", NULL);\r
-\r
-     fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,\r
-                                GetCurrentProcess(), &hChildStdoutRdDup, 0,\r
-                                FALSE, DUPLICATE_SAME_ACCESS);\r
-     if (!fSuccess)\r
-         return win32_error("DuplicateHandle", NULL);\r
-\r
-     /* Close the inheritable version of ChildStdout\r
-        that we're using. */\r
-     CloseHandle(hChildStdoutRd);\r
-\r
-     if (n != POPEN_4) {\r
-         if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))\r
-             return win32_error("CreatePipe", NULL);\r
-         fSuccess = DuplicateHandle(GetCurrentProcess(),\r
-                                    hChildStderrRd,\r
-                                    GetCurrentProcess(),\r
-                                    &hChildStderrRdDup, 0,\r
-                                    FALSE, DUPLICATE_SAME_ACCESS);\r
-         if (!fSuccess)\r
-             return win32_error("DuplicateHandle", NULL);\r
-         /* Close the inheritable version of ChildStdErr that we're using. */\r
-         CloseHandle(hChildStderrRd);\r
-     }\r
-\r
-     switch (n) {\r
-     case POPEN_1:\r
-         switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) {\r
-         case _O_WRONLY | _O_TEXT:\r
-             /* Case for writing to child Stdin in text mode. */\r
-             fd1 = _open_osfhandle((Py_intptr_t)hChildStdinWrDup, mode);\r
-             f1 = _fdopen(fd1, "w");\r
-             f = PyFile_FromFile(f1, cmdstring, "w", _PyPclose);\r
-             PyFile_SetBufSize(f, 0);\r
-             /* We don't care about these pipes anymore, so close them. */\r
-             CloseHandle(hChildStdoutRdDup);\r
-             CloseHandle(hChildStderrRdDup);\r
-             break;\r
-\r
-         case _O_RDONLY | _O_TEXT:\r
-             /* Case for reading from child Stdout in text mode. */\r
-             fd1 = _open_osfhandle((Py_intptr_t)hChildStdoutRdDup, mode);\r
-             f1 = _fdopen(fd1, "r");\r
-             f = PyFile_FromFile(f1, cmdstring, "r", _PyPclose);\r
-             PyFile_SetBufSize(f, 0);\r
-             /* We don't care about these pipes anymore, so close them. */\r
-             CloseHandle(hChildStdinWrDup);\r
-             CloseHandle(hChildStderrRdDup);\r
-             break;\r
-\r
-         case _O_RDONLY | _O_BINARY:\r
-             /* Case for readinig from child Stdout in binary mode. */\r
-             fd1 = _open_osfhandle((Py_intptr_t)hChildStdoutRdDup, mode);\r
-             f1 = _fdopen(fd1, "rb");\r
-             f = PyFile_FromFile(f1, cmdstring, "rb", _PyPclose);\r
-             PyFile_SetBufSize(f, 0);\r
-             /* We don't care about these pipes anymore, so close them. */\r
-             CloseHandle(hChildStdinWrDup);\r
-             CloseHandle(hChildStderrRdDup);\r
-             break;\r
-\r
-         case _O_WRONLY | _O_BINARY:\r
-             /* Case for writing to child Stdin in binary mode. */\r
-             fd1 = _open_osfhandle((Py_intptr_t)hChildStdinWrDup, mode);\r
-             f1 = _fdopen(fd1, "wb");\r
-             f = PyFile_FromFile(f1, cmdstring, "wb", _PyPclose);\r
-             PyFile_SetBufSize(f, 0);\r
-             /* We don't care about these pipes anymore, so close them. */\r
-             CloseHandle(hChildStdoutRdDup);\r
-             CloseHandle(hChildStderrRdDup);\r
-             break;\r
-         }\r
-         file_count = 1;\r
-         break;\r
-\r
-     case POPEN_2:\r
-     case POPEN_4:\r
-     {\r
-         char *m1, *m2;\r
-         PyObject *p1, *p2;\r
-\r
-         if (mode & _O_TEXT) {\r
-             m1 = "r";\r
-             m2 = "w";\r
-         } else {\r
-             m1 = "rb";\r
-             m2 = "wb";\r
-         }\r
-\r
-         fd1 = _open_osfhandle((Py_intptr_t)hChildStdinWrDup, mode);\r
-         f1 = _fdopen(fd1, m2);\r
-         fd2 = _open_osfhandle((Py_intptr_t)hChildStdoutRdDup, mode);\r
-         f2 = _fdopen(fd2, m1);\r
-         p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);\r
-         PyFile_SetBufSize(p1, 0);\r
-         p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);\r
-         PyFile_SetBufSize(p2, 0);\r
-\r
-         if (n != 4)\r
-             CloseHandle(hChildStderrRdDup);\r
-\r
-         f = PyTuple_Pack(2,p1,p2);\r
-         Py_XDECREF(p1);\r
-         Py_XDECREF(p2);\r
-         file_count = 2;\r
-         break;\r
-     }\r
-\r
-     case POPEN_3:\r
-     {\r
-         char *m1, *m2;\r
-         PyObject *p1, *p2, *p3;\r
-\r
-         if (mode & _O_TEXT) {\r
-             m1 = "r";\r
-             m2 = "w";\r
-         } else {\r
-             m1 = "rb";\r
-             m2 = "wb";\r
-         }\r
-\r
-         fd1 = _open_osfhandle((Py_intptr_t)hChildStdinWrDup, mode);\r
-         f1 = _fdopen(fd1, m2);\r
-         fd2 = _open_osfhandle((Py_intptr_t)hChildStdoutRdDup, mode);\r
-         f2 = _fdopen(fd2, m1);\r
-         fd3 = _open_osfhandle((Py_intptr_t)hChildStderrRdDup, mode);\r
-         f3 = _fdopen(fd3, m1);\r
-         p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);\r
-         p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);\r
-         p3 = PyFile_FromFile(f3, cmdstring, m1, _PyPclose);\r
-         PyFile_SetBufSize(p1, 0);\r
-         PyFile_SetBufSize(p2, 0);\r
-         PyFile_SetBufSize(p3, 0);\r
-         f = PyTuple_Pack(3,p1,p2,p3);\r
-         Py_XDECREF(p1);\r
-         Py_XDECREF(p2);\r
-         Py_XDECREF(p3);\r
-         file_count = 3;\r
-         break;\r
-     }\r
-     }\r
-\r
-     if (n == POPEN_4) {\r
-         if (!_PyPopenCreateProcess(cmdstring,\r
-                                    hChildStdinRd,\r
-                                    hChildStdoutWr,\r
-                                    hChildStdoutWr,\r
-                                    &hProcess))\r
-             return NULL;\r
-     }\r
-     else {\r
-         if (!_PyPopenCreateProcess(cmdstring,\r
-                                    hChildStdinRd,\r
-                                    hChildStdoutWr,\r
-                                    hChildStderrWr,\r
-                                    &hProcess))\r
-             return NULL;\r
-     }\r
-\r
-     /*\r
-      * Insert the files we've created into the process dictionary\r
-      * all referencing the list with the process handle and the\r
-      * initial number of files (see description below in _PyPclose).\r
-      * Since if _PyPclose later tried to wait on a process when all\r
-      * handles weren't closed, it could create a deadlock with the\r
-      * child, we spend some energy here to try to ensure that we\r
-      * either insert all file handles into the dictionary or none\r
-      * at all.  It's a little clumsy with the various popen modes\r
-      * and variable number of files involved.\r
-      */\r
-     if (!_PyPopenProcs) {\r
-         _PyPopenProcs = PyDict_New();\r
-     }\r
-\r
-     if (_PyPopenProcs) {\r
-         PyObject *procObj, *hProcessObj, *intObj, *fileObj[3];\r
-         int ins_rc[3];\r
-\r
-         fileObj[0] = fileObj[1] = fileObj[2] = NULL;\r
-         ins_rc[0]  = ins_rc[1]  = ins_rc[2]  = 0;\r
-\r
-         procObj = PyList_New(2);\r
-         hProcessObj = PyLong_FromVoidPtr(hProcess);\r
-         intObj = PyInt_FromLong(file_count);\r
-\r
-         if (procObj && hProcessObj && intObj) {\r
-             PyList_SetItem(procObj,0,hProcessObj);\r
-             PyList_SetItem(procObj,1,intObj);\r
-\r
-             fileObj[0] = PyLong_FromVoidPtr(f1);\r
-             if (fileObj[0]) {\r
-                ins_rc[0] = PyDict_SetItem(_PyPopenProcs,\r
-                                           fileObj[0],\r
-                                           procObj);\r
-             }\r
-             if (file_count >= 2) {\r
-                 fileObj[1] = PyLong_FromVoidPtr(f2);\r
-                 if (fileObj[1]) {\r
-                    ins_rc[1] = PyDict_SetItem(_PyPopenProcs,\r
-                                               fileObj[1],\r
-                                               procObj);\r
-                 }\r
-             }\r
-             if (file_count >= 3) {\r
-                 fileObj[2] = PyLong_FromVoidPtr(f3);\r
-                 if (fileObj[2]) {\r
-                    ins_rc[2] = PyDict_SetItem(_PyPopenProcs,\r
-                                               fileObj[2],\r
-                                               procObj);\r
-                 }\r
-             }\r
-\r
-             if (ins_rc[0] < 0 || !fileObj[0] ||\r
-                 ins_rc[1] < 0 || (file_count > 1 && !fileObj[1]) ||\r
-                 ins_rc[2] < 0 || (file_count > 2 && !fileObj[2])) {\r
-                 /* Something failed - remove any dictionary\r
-                  * entries that did make it.\r
-                  */\r
-                 if (!ins_rc[0] && fileObj[0]) {\r
-                     PyDict_DelItem(_PyPopenProcs,\r
-                                    fileObj[0]);\r
-                 }\r
-                 if (!ins_rc[1] && fileObj[1]) {\r
-                     PyDict_DelItem(_PyPopenProcs,\r
-                                    fileObj[1]);\r
-                 }\r
-                 if (!ins_rc[2] && fileObj[2]) {\r
-                     PyDict_DelItem(_PyPopenProcs,\r
-                                    fileObj[2]);\r
-                 }\r
-             }\r
-         }\r
-\r
-         /*\r
-          * Clean up our localized references for the dictionary keys\r
-          * and value since PyDict_SetItem will Py_INCREF any copies\r
-          * that got placed in the dictionary.\r
-          */\r
-         Py_XDECREF(procObj);\r
-         Py_XDECREF(fileObj[0]);\r
-         Py_XDECREF(fileObj[1]);\r
-         Py_XDECREF(fileObj[2]);\r
-     }\r
-\r
-     /* Child is launched. Close the parents copy of those pipe\r
-      * handles that only the child should have open.  You need to\r
-      * make sure that no handles to the write end of the output pipe\r
-      * are maintained in this process or else the pipe will not close\r
-      * when the child process exits and the ReadFile will hang. */\r
-\r
-     if (!CloseHandle(hChildStdinRd))\r
-         return win32_error("CloseHandle", NULL);\r
-\r
-     if (!CloseHandle(hChildStdoutWr))\r
-         return win32_error("CloseHandle", NULL);\r
-\r
-     if ((n != 4) && (!CloseHandle(hChildStderrWr)))\r
-         return win32_error("CloseHandle", NULL);\r
-\r
-     return f;\r
+    int fd;\r
+    pid_t pgid;\r
+    if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd))\r
+        return NULL;\r
+    pgid = tcgetpgrp(fd);\r
+    if (pgid < 0)\r
+        return posix_error();\r
+    return PyLong_FromPid(pgid);\r
 }\r
 }\r
+#endif /* HAVE_TCGETPGRP */\r
 \r
 \r
-/*\r
- * Wrapper for fclose() to use for popen* files, so we can retrieve the\r
- * exit code for the child process and return as a result of the close.\r
- *\r
- * This function uses the _PyPopenProcs dictionary in order to map the\r
- * input file pointer to information about the process that was\r
- * originally created by the popen* call that created the file pointer.\r
- * The dictionary uses the file pointer as a key (with one entry\r
- * inserted for each file returned by the original popen* call) and a\r
- * single list object as the value for all files from a single call.\r
- * The list object contains the Win32 process handle at [0], and a file\r
- * count at [1], which is initialized to the total number of file\r
- * handles using that list.\r
- *\r
- * This function closes whichever handle it is passed, and decrements\r
- * the file count in the dictionary for the process handle pointed to\r
- * by this file.  On the last close (when the file count reaches zero),\r
- * this function will wait for the child process and then return its\r
- * exit code as the result of the close() operation.  This permits the\r
- * files to be closed in any order - it is always the close() of the\r
- * final handle that will return the exit code.\r
- *\r
- * NOTE: This function is currently called with the GIL released.\r
- * hence we use the GILState API to manage our state.\r
- */\r
-\r
-static int _PyPclose(FILE *file)\r
-{\r
-    int result;\r
-    DWORD exit_code;\r
-    HANDLE hProcess;\r
-    PyObject *procObj, *hProcessObj, *intObj, *fileObj;\r
-    long file_count;\r
-#ifdef WITH_THREAD\r
-    PyGILState_STATE state;\r
-#endif\r
-\r
-    /* Close the file handle first, to ensure it can't block the\r
-     * child from exiting if it's the last handle.\r
-     */\r
-    result = fclose(file);\r
-#ifdef WITH_THREAD\r
-    state = PyGILState_Ensure();\r
-#endif\r
-    if (_PyPopenProcs) {\r
-        if ((fileObj = PyLong_FromVoidPtr(file)) != NULL &&\r
-            (procObj = PyDict_GetItem(_PyPopenProcs,\r
-                                      fileObj)) != NULL &&\r
-            (hProcessObj = PyList_GetItem(procObj,0)) != NULL &&\r
-            (intObj = PyList_GetItem(procObj,1)) != NULL) {\r
-\r
-            hProcess = PyLong_AsVoidPtr(hProcessObj);\r
-            file_count = PyInt_AsLong(intObj);\r
-\r
-            if (file_count > 1) {\r
-                /* Still other files referencing process */\r
-                file_count--;\r
-                PyList_SetItem(procObj,1,\r
-                               PyInt_FromLong(file_count));\r
-            } else {\r
-                /* Last file for this process */\r
-                if (result != EOF &&\r
-                    WaitForSingleObject(hProcess, INFINITE) != WAIT_FAILED &&\r
-                    GetExitCodeProcess(hProcess, &exit_code)) {\r
-                    /* Possible truncation here in 16-bit environments, but\r
-                     * real exit codes are just the lower byte in any event.\r
-                     */\r
-                    result = exit_code;\r
-                } else {\r
-                    /* Indicate failure - this will cause the file object\r
-                     * to raise an I/O error and translate the last Win32\r
-                     * error code from errno.  We do have a problem with\r
-                     * last errors that overlap the normal errno table,\r
-                     * but that's a consistent problem with the file object.\r
-                     */\r
-                    if (result != EOF) {\r
-                        /* If the error wasn't from the fclose(), then\r
-                         * set errno for the file object error handling.\r
-                         */\r
-                        errno = GetLastError();\r
-                    }\r
-                    result = -1;\r
-                }\r
-\r
-                /* Free up the native handle at this point */\r
-                CloseHandle(hProcess);\r
-            }\r
-\r
-            /* Remove this file pointer from dictionary */\r
-            PyDict_DelItem(_PyPopenProcs, fileObj);\r
 \r
 \r
-            if (PyDict_Size(_PyPopenProcs) == 0) {\r
-                Py_DECREF(_PyPopenProcs);\r
-                _PyPopenProcs = NULL;\r
-            }\r
+#ifdef HAVE_TCSETPGRP\r
+PyDoc_STRVAR(posix_tcsetpgrp__doc__,\r
+"tcsetpgrp(fd, pgid)\n\n\\r
+Set the process group associated with the terminal given by a fd.");\r
 \r
 \r
-        } /* if object retrieval ok */\r
+static PyObject *\r
+posix_tcsetpgrp(PyObject *self, PyObject *args)\r
+{\r
+    int fd;\r
+    pid_t pgid;\r
+    if (!PyArg_ParseTuple(args, "i" PARSE_PID ":tcsetpgrp", &fd, &pgid))\r
+        return NULL;\r
+    if (tcsetpgrp(fd, pgid) < 0)\r
+        return posix_error();\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+#endif /* HAVE_TCSETPGRP */\r
 \r
 \r
-        Py_XDECREF(fileObj);\r
-    } /* if _PyPopenProcs */\r
+/* Functions acting on file descriptors */\r
 \r
 \r
-#ifdef WITH_THREAD\r
-    PyGILState_Release(state);\r
-#endif\r
-    return result;\r
-}\r
+PyDoc_STRVAR(posix_open__doc__,\r
+"open(filename, flag [, mode=0777]) -> fd\n\n\\r
+Open a file (for low level IO).");\r
 \r
 \r
-#else /* which OS? */\r
 static PyObject *\r
 static PyObject *\r
-posix_popen(PyObject *self, PyObject *args)\r
+posix_open(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    char *name;\r
-    char *mode = "r";\r
-    int bufsize = -1;\r
-    FILE *fp;\r
-    PyObject *f;\r
-    if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))\r
+    char *file = NULL;\r
+    int flag;\r
+    int mode = 0777;\r
+    int fd;\r
+\r
+    if (!PyArg_ParseTuple(args, "eti|i",\r
+                          Py_FileSystemDefaultEncoding, &file,\r
+                          &flag, &mode))\r
         return NULL;\r
         return NULL;\r
-    /* Strip mode of binary or text modifiers */\r
-    if (strcmp(mode, "rb") == 0 || strcmp(mode, "rt") == 0)\r
-        mode = "r";\r
-    else if (strcmp(mode, "wb") == 0 || strcmp(mode, "wt") == 0)\r
-        mode = "w";\r
+\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    fp = popen(name, mode);\r
+    fd = open(file, flag, mode);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-    if (fp == NULL)\r
-        return posix_error();\r
-    f = PyFile_FromFile(fp, name, mode, pclose);\r
-    if (f != NULL)\r
-        PyFile_SetBufSize(f, bufsize);\r
-    return f;\r
+    if (fd < 0)\r
+        return posix_error_with_allocated_filename(file);\r
+    PyMem_Free(file);\r
+    return PyInt_FromLong((long)fd);\r
 }\r
 \r
 }\r
 \r
-#endif /* PYOS_??? */\r
-#endif /* HAVE_POPEN */\r
-\r
 \r
 \r
-#ifdef HAVE_SETUID\r
-PyDoc_STRVAR(posix_setuid__doc__,\r
-"setuid(uid)\n\n\\r
-Set the current process's user id.");\r
+PyDoc_STRVAR(posix_close__doc__,\r
+"close(fd)\n\n\\r
+Close a file descriptor (for low level IO).");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setuid(PyObject *self, PyObject *args)\r
+posix_close(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    long uid_arg;\r
-    uid_t uid;\r
-    if (!PyArg_ParseTuple(args, "l:setuid", &uid_arg))\r
-        return NULL;\r
-    uid = uid_arg;\r
-    if (uid != uid_arg) {\r
-        PyErr_SetString(PyExc_OverflowError, "user id too big");\r
+    int fd, res;\r
+    if (!PyArg_ParseTuple(args, "i:close", &fd))\r
         return NULL;\r
         return NULL;\r
-    }\r
-    if (setuid(uid) < 0)\r
+    if (!_PyVerify_fd(fd))\r
+        return posix_error();\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = close(fd);\r
+    Py_END_ALLOW_THREADS\r
+    if (res < 0)\r
         return posix_error();\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
         return posix_error();\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
-#endif /* HAVE_SETUID */\r
 \r
 \r
 \r
 \r
-#ifdef HAVE_SETEUID\r
-PyDoc_STRVAR(posix_seteuid__doc__,\r
-"seteuid(uid)\n\n\\r
-Set the current process's effective user id.");\r
+PyDoc_STRVAR(posix_closerange__doc__,\r
+"closerange(fd_low, fd_high)\n\n\\r
+Closes all file descriptors in [fd_low, fd_high), ignoring errors.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_seteuid (PyObject *self, PyObject *args)\r
+posix_closerange(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    long euid_arg;\r
-    uid_t euid;\r
-    if (!PyArg_ParseTuple(args, "l", &euid_arg))\r
-        return NULL;\r
-    euid = euid_arg;\r
-    if (euid != euid_arg) {\r
-        PyErr_SetString(PyExc_OverflowError, "user id too big");\r
+    int fd_from, fd_to, i;\r
+    if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))\r
         return NULL;\r
         return NULL;\r
-    }\r
-    if (seteuid(euid) < 0) {\r
-        return posix_error();\r
-    } else {\r
-        Py_INCREF(Py_None);\r
-        return Py_None;\r
-    }\r
+    Py_BEGIN_ALLOW_THREADS\r
+    for (i = fd_from; i < fd_to; i++)\r
+        if (_PyVerify_fd(i))\r
+            close(i);\r
+    Py_END_ALLOW_THREADS\r
+    Py_RETURN_NONE;\r
 }\r
 }\r
-#endif /* HAVE_SETEUID */\r
 \r
 \r
-#ifdef HAVE_SETEGID\r
-PyDoc_STRVAR(posix_setegid__doc__,\r
-"setegid(gid)\n\n\\r
-Set the current process's effective group id.");\r
+\r
+PyDoc_STRVAR(posix_dup__doc__,\r
+"dup(fd) -> fd2\n\n\\r
+Return a duplicate of a file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setegid (PyObject *self, PyObject *args)\r
+posix_dup(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    long egid_arg;\r
-    gid_t egid;\r
-    if (!PyArg_ParseTuple(args, "l", &egid_arg))\r
-        return NULL;\r
-    egid = egid_arg;\r
-    if (egid != egid_arg) {\r
-        PyErr_SetString(PyExc_OverflowError, "group id too big");\r
+    int fd;\r
+    if (!PyArg_ParseTuple(args, "i:dup", &fd))\r
         return NULL;\r
         return NULL;\r
-    }\r
-    if (setegid(egid) < 0) {\r
+    if (!_PyVerify_fd(fd))\r
         return posix_error();\r
         return posix_error();\r
-    } else {\r
-        Py_INCREF(Py_None);\r
-        return Py_None;\r
-    }\r
+    Py_BEGIN_ALLOW_THREADS\r
+    fd = dup(fd);\r
+    Py_END_ALLOW_THREADS\r
+    if (fd < 0)\r
+        return posix_error();\r
+    return PyInt_FromLong((long)fd);\r
 }\r
 }\r
-#endif /* HAVE_SETEGID */\r
 \r
 \r
-#ifdef HAVE_SETREUID\r
-PyDoc_STRVAR(posix_setreuid__doc__,\r
-"setreuid(ruid, euid)\n\n\\r
-Set the current process's real and effective user ids.");\r
+\r
+PyDoc_STRVAR(posix_dup2__doc__,\r
+"dup2(old_fd, new_fd)\n\n\\r
+Duplicate file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setreuid (PyObject *self, PyObject *args)\r
+posix_dup2(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    long ruid_arg, euid_arg;\r
-    uid_t ruid, euid;\r
-    if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg))\r
-        return NULL;\r
-    if (ruid_arg == -1)\r
-        ruid = (uid_t)-1;  /* let the compiler choose how -1 fits */\r
-    else\r
-        ruid = ruid_arg;  /* otherwise, assign from our long */\r
-    if (euid_arg == -1)\r
-        euid = (uid_t)-1;\r
-    else\r
-        euid = euid_arg;\r
-    if ((euid_arg != -1 && euid != euid_arg) ||\r
-        (ruid_arg != -1 && ruid != ruid_arg)) {\r
-        PyErr_SetString(PyExc_OverflowError, "user id too big");\r
-        return NULL;\r
-    }\r
-    if (setreuid(ruid, euid) < 0) {\r
-        return posix_error();\r
-    } else {\r
-        Py_INCREF(Py_None);\r
-        return Py_None;\r
-    }\r
-}\r
-#endif /* HAVE_SETREUID */\r
-\r
-#ifdef HAVE_SETREGID\r
-PyDoc_STRVAR(posix_setregid__doc__,\r
-"setregid(rgid, egid)\n\n\\r
-Set the current process's real and effective group ids.");\r
-\r
-static PyObject *\r
-posix_setregid (PyObject *self, PyObject *args)\r
-{\r
-    long rgid_arg, egid_arg;\r
-    gid_t rgid, egid;\r
-    if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg))\r
-        return NULL;\r
-    if (rgid_arg == -1)\r
-        rgid = (gid_t)-1;  /* let the compiler choose how -1 fits */\r
-    else\r
-        rgid = rgid_arg;  /* otherwise, assign from our long */\r
-    if (egid_arg == -1)\r
-        egid = (gid_t)-1;\r
-    else\r
-        egid = egid_arg;\r
-    if ((egid_arg != -1 && egid != egid_arg) ||\r
-        (rgid_arg != -1 && rgid != rgid_arg)) {\r
-        PyErr_SetString(PyExc_OverflowError, "group id too big");\r
+    int fd, fd2, res;\r
+    if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2))\r
         return NULL;\r
         return NULL;\r
-    }\r
-    if (setregid(rgid, egid) < 0) {\r
+    if (!_PyVerify_fd_dup2(fd, fd2))\r
         return posix_error();\r
         return posix_error();\r
-    } else {\r
-        Py_INCREF(Py_None);\r
-        return Py_None;\r
-    }\r
-}\r
-#endif /* HAVE_SETREGID */\r
-\r
-#ifdef HAVE_SETGID\r
-PyDoc_STRVAR(posix_setgid__doc__,\r
-"setgid(gid)\n\n\\r
-Set the current process's group id.");\r
-\r
-static PyObject *\r
-posix_setgid(PyObject *self, PyObject *args)\r
-{\r
-    long gid_arg;\r
-    gid_t gid;\r
-    if (!PyArg_ParseTuple(args, "l:setgid", &gid_arg))\r
-        return NULL;\r
-    gid = gid_arg;\r
-    if (gid != gid_arg) {\r
-        PyErr_SetString(PyExc_OverflowError, "group id too big");\r
-        return NULL;\r
-    }\r
-    if (setgid(gid) < 0)\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = dup2(fd, fd2);\r
+    Py_END_ALLOW_THREADS\r
+    if (res < 0)\r
         return posix_error();\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
         return posix_error();\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
-#endif /* HAVE_SETGID */\r
 \r
 \r
-#ifdef HAVE_SETGROUPS\r
-PyDoc_STRVAR(posix_setgroups__doc__,\r
-"setgroups(list)\n\n\\r
-Set the groups of the current process to list.");\r
+\r
+PyDoc_STRVAR(posix_lseek__doc__,\r
+"lseek(fd, pos, how) -> newpos\n\n\\r
+Set the current position of a file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setgroups(PyObject *self, PyObject *groups)\r
+posix_lseek(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int i, len;\r
-    gid_t grouplist[MAX_GROUPS];\r
-\r
-    if (!PySequence_Check(groups)) {\r
-        PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence");\r
+    int fd, how;\r
+    off_t pos, res;\r
+    PyObject *posobj;\r
+    if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))\r
         return NULL;\r
         return NULL;\r
+#ifdef SEEK_SET\r
+    /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */\r
+    switch (how) {\r
+    case 0: how = SEEK_SET; break;\r
+    case 1: how = SEEK_CUR; break;\r
+    case 2: how = SEEK_END; break;\r
     }\r
     }\r
-    len = PySequence_Size(groups);\r
-    if (len > MAX_GROUPS) {\r
-        PyErr_SetString(PyExc_ValueError, "too many groups");\r
+#endif /* SEEK_END */\r
+\r
+#if !defined(HAVE_LARGEFILE_SUPPORT)\r
+    pos = PyInt_AsLong(posobj);\r
+#else\r
+    pos = PyLong_Check(posobj) ?\r
+        PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);\r
+#endif\r
+    if (PyErr_Occurred())\r
         return NULL;\r
         return NULL;\r
-    }\r
-    for(i = 0; i < len; i++) {\r
-        PyObject *elem;\r
-        elem = PySequence_GetItem(groups, i);\r
-        if (!elem)\r
-            return NULL;\r
-        if (!PyInt_Check(elem)) {\r
-            if (!PyLong_Check(elem)) {\r
-                PyErr_SetString(PyExc_TypeError,\r
-                                "groups must be integers");\r
-                Py_DECREF(elem);\r
-                return NULL;\r
-            } else {\r
-                unsigned long x = PyLong_AsUnsignedLong(elem);\r
-                if (PyErr_Occurred()) {\r
-                    PyErr_SetString(PyExc_TypeError,\r
-                                    "group id too big");\r
-                    Py_DECREF(elem);\r
-                    return NULL;\r
-                }\r
-                grouplist[i] = x;\r
-                /* read back to see if it fits in gid_t */\r
-                if (grouplist[i] != x) {\r
-                    PyErr_SetString(PyExc_TypeError,\r
-                                    "group id too big");\r
-                    Py_DECREF(elem);\r
-                    return NULL;\r
-                }\r
-            }\r
-        } else {\r
-            long x  = PyInt_AsLong(elem);\r
-            grouplist[i] = x;\r
-            if (grouplist[i] != x) {\r
-                PyErr_SetString(PyExc_TypeError,\r
-                                "group id too big");\r
-                Py_DECREF(elem);\r
-                return NULL;\r
-            }\r
-        }\r
-        Py_DECREF(elem);\r
-    }\r
 \r
 \r
-    if (setgroups(len, grouplist) < 0)\r
+    if (!_PyVerify_fd(fd))\r
         return posix_error();\r
         return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif /* HAVE_SETGROUPS */\r
-\r
-#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)\r
-static PyObject *\r
-wait_helper(pid_t pid, int status, struct rusage *ru)\r
-{\r
-    PyObject *result;\r
-    static PyObject *struct_rusage;\r
-\r
-    if (pid == -1)\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = lseek(fd, pos, how);\r
+    Py_END_ALLOW_THREADS\r
+    if (res < 0)\r
         return posix_error();\r
 \r
         return posix_error();\r
 \r
-    if (struct_rusage == NULL) {\r
-        PyObject *m = PyImport_ImportModuleNoBlock("resource");\r
-        if (m == NULL)\r
-            return NULL;\r
-        struct_rusage = PyObject_GetAttrString(m, "struct_rusage");\r
-        Py_DECREF(m);\r
-        if (struct_rusage == NULL)\r
-            return NULL;\r
-    }\r
-\r
-    /* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */\r
-    result = PyStructSequence_New((PyTypeObject*) struct_rusage);\r
-    if (!result)\r
-        return NULL;\r
-\r
-#ifndef doubletime\r
-#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)\r
+#if !defined(HAVE_LARGEFILE_SUPPORT)\r
+    return PyInt_FromLong(res);\r
+#else\r
+    return PyLong_FromLongLong(res);\r
 #endif\r
 #endif\r
-\r
-    PyStructSequence_SET_ITEM(result, 0,\r
-                              PyFloat_FromDouble(doubletime(ru->ru_utime)));\r
-    PyStructSequence_SET_ITEM(result, 1,\r
-                              PyFloat_FromDouble(doubletime(ru->ru_stime)));\r
-#define SET_INT(result, index, value)\\r
-        PyStructSequence_SET_ITEM(result, index, PyInt_FromLong(value))\r
-    SET_INT(result, 2, ru->ru_maxrss);\r
-    SET_INT(result, 3, ru->ru_ixrss);\r
-    SET_INT(result, 4, ru->ru_idrss);\r
-    SET_INT(result, 5, ru->ru_isrss);\r
-    SET_INT(result, 6, ru->ru_minflt);\r
-    SET_INT(result, 7, ru->ru_majflt);\r
-    SET_INT(result, 8, ru->ru_nswap);\r
-    SET_INT(result, 9, ru->ru_inblock);\r
-    SET_INT(result, 10, ru->ru_oublock);\r
-    SET_INT(result, 11, ru->ru_msgsnd);\r
-    SET_INT(result, 12, ru->ru_msgrcv);\r
-    SET_INT(result, 13, ru->ru_nsignals);\r
-    SET_INT(result, 14, ru->ru_nvcsw);\r
-    SET_INT(result, 15, ru->ru_nivcsw);\r
-#undef SET_INT\r
-\r
-    if (PyErr_Occurred()) {\r
-        Py_DECREF(result);\r
-        return NULL;\r
-    }\r
-\r
-    return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);\r
 }\r
 }\r
-#endif /* HAVE_WAIT3 || HAVE_WAIT4 */\r
 \r
 \r
-#ifdef HAVE_WAIT3\r
-PyDoc_STRVAR(posix_wait3__doc__,\r
-"wait3(options) -> (pid, status, rusage)\n\n\\r
-Wait for completion of a child process.");\r
+\r
+PyDoc_STRVAR(posix_read__doc__,\r
+"read(fd, buffersize) -> string\n\n\\r
+Read a file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_wait3(PyObject *self, PyObject *args)\r
+posix_read(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    int options;\r
-    struct rusage ru;\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:wait3", &options))\r
+    int fd, size, n;\r
+    PyObject *buffer;\r
+    if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))\r
         return NULL;\r
         return NULL;\r
-\r
+    if (size < 0) {\r
+        errno = EINVAL;\r
+        return posix_error();\r
+    }\r
+    buffer = PyString_FromStringAndSize((char *)NULL, size);\r
+    if (buffer == NULL)\r
+        return NULL;\r
+    if (!_PyVerify_fd(fd)) {\r
+        Py_DECREF(buffer);\r
+        return posix_error();\r
+    }\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    pid = wait3(&status, options, &ru);\r
+    n = read(fd, PyString_AsString(buffer), size);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-\r
-    return wait_helper(pid, WAIT_STATUS_INT(status), &ru);\r
+    if (n < 0) {\r
+        Py_DECREF(buffer);\r
+        return posix_error();\r
+    }\r
+    if (n != size)\r
+        _PyString_Resize(&buffer, n);\r
+    return buffer;\r
 }\r
 }\r
-#endif /* HAVE_WAIT3 */\r
 \r
 \r
-#ifdef HAVE_WAIT4\r
-PyDoc_STRVAR(posix_wait4__doc__,\r
-"wait4(pid, options) -> (pid, status, rusage)\n\n\\r
-Wait for completion of a given child process.");\r
+\r
+PyDoc_STRVAR(posix_write__doc__,\r
+"write(fd, string) -> byteswritten\n\n\\r
+Write a string to a file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_wait4(PyObject *self, PyObject *args)\r
+posix_write(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    int options;\r
-    struct rusage ru;\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
+    Py_buffer pbuf;\r
+    int fd;\r
+    Py_ssize_t size;\r
 \r
 \r
-    if (!PyArg_ParseTuple(args, PARSE_PID "i:wait4", &pid, &options))\r
+    if (!PyArg_ParseTuple(args, "is*:write", &fd, &pbuf))\r
         return NULL;\r
         return NULL;\r
-\r
+    if (!_PyVerify_fd(fd)) {\r
+        PyBuffer_Release(&pbuf);\r
+        return posix_error();\r
+    }\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    pid = wait4(pid, &status, options, &ru);\r
+    size = write(fd, pbuf.buf, (size_t)pbuf.len);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-\r
-    return wait_helper(pid, WAIT_STATUS_INT(status), &ru);\r
+    PyBuffer_Release(&pbuf);\r
+    if (size < 0)\r
+        return posix_error();\r
+    return PyInt_FromSsize_t(size);\r
 }\r
 }\r
-#endif /* HAVE_WAIT4 */\r
 \r
 \r
-#ifdef HAVE_WAITPID\r
-PyDoc_STRVAR(posix_waitpid__doc__,\r
-"waitpid(pid, options) -> (pid, status)\n\n\\r
-Wait for completion of a given child process.");\r
+\r
+PyDoc_STRVAR(posix_fstat__doc__,\r
+"fstat(fd) -> stat result\n\n\\r
+Like stat(), but for an open file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_waitpid(PyObject *self, PyObject *args)\r
+posix_fstat(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    int options;\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, PARSE_PID "i:waitpid", &pid, &options))\r
+    int fd;\r
+    STRUCT_STAT st;\r
+    int res;\r
+    if (!PyArg_ParseTuple(args, "i:fstat", &fd))\r
         return NULL;\r
         return NULL;\r
+    if (!_PyVerify_fd(fd))\r
+        return posix_error();\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    pid = waitpid(pid, &status, options);\r
+    res = FSTAT(fd, &st);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-    if (pid == -1)\r
-        return posix_error();\r
+    if (res != 0) {\r
+      return posix_error();\r
+    }\r
 \r
 \r
-    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));\r
+    return _pystat_fromstructstat(&st);\r
 }\r
 \r
 }\r
 \r
-#elif defined(HAVE_CWAIT)\r
 \r
 \r
-/* MS C has a variant of waitpid() that's usable for most purposes. */\r
-PyDoc_STRVAR(posix_waitpid__doc__,\r
-"waitpid(pid, options) -> (pid, status << 8)\n\n"\r
-"Wait for completion of a given process.  options is ignored on Windows.");\r
+PyDoc_STRVAR(posix_fdopen__doc__,\r
+"fdopen(fd [, mode='r' [, bufsize]]) -> file_object\n\n\\r
+Return an open file object connected to a file descriptor.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_waitpid(PyObject *self, PyObject *args)\r
+posix_fdopen(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    Py_intptr_t pid;\r
-    int status, options;\r
+    int fd;\r
+    char *orgmode = "r";\r
+    int bufsize = -1;\r
+    FILE *fp;\r
+    PyObject *f;\r
+    char *mode;\r
+    if (!PyArg_ParseTuple(args, "i|si", &fd, &orgmode, &bufsize))\r
+        return NULL;\r
 \r
 \r
-    if (!PyArg_ParseTuple(args, PARSE_PID "i:waitpid", &pid, &options))\r
+    /* Sanitize mode.  See fileobject.c */\r
+    mode = PyMem_MALLOC(strlen(orgmode)+3);\r
+    if (!mode) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    strcpy(mode, orgmode);\r
+    if (_PyFile_SanitizeMode(mode)) {\r
+        PyMem_FREE(mode);\r
         return NULL;\r
         return NULL;\r
+    }\r
+    if (!_PyVerify_fd(fd))\r
+        return posix_error();\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    pid = _cwait(&status, pid, options);\r
+#if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)\r
+    if (mode[0] == 'a') {\r
+        /* try to make sure the O_APPEND flag is set */\r
+        int flags;\r
+        flags = fcntl(fd, F_GETFL);\r
+        if (flags != -1)\r
+            fcntl(fd, F_SETFL, flags | O_APPEND);\r
+        fp = fdopen(fd, mode);\r
+        if (fp == NULL && flags != -1)\r
+            /* restore old mode if fdopen failed */\r
+            fcntl(fd, F_SETFL, flags);\r
+    } else {\r
+        fp = fdopen(fd, mode);\r
+    }\r
+#else\r
+    fp = fdopen(fd, mode);\r
+#endif\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-    if (pid == -1)\r
+    PyMem_FREE(mode);\r
+    if (fp == NULL)\r
         return posix_error();\r
         return posix_error();\r
-\r
-    /* shift the status left a byte so this is more like the POSIX waitpid */\r
-    return Py_BuildValue("Ni", PyLong_FromPid(pid), status << 8);\r
+    f = PyFile_FromFile(fp, "<fdopen>", orgmode, fclose);\r
+    if (f != NULL)\r
+        PyFile_SetBufSize(f, bufsize);\r
+    return f;\r
 }\r
 }\r
-#endif /* HAVE_WAITPID || HAVE_CWAIT */\r
 \r
 \r
-#ifdef HAVE_WAIT\r
-PyDoc_STRVAR(posix_wait__doc__,\r
-"wait() -> (pid, status)\n\n\\r
-Wait for completion of a child process.");\r
+PyDoc_STRVAR(posix_isatty__doc__,\r
+"isatty(fd) -> bool\n\n\\r
+Return True if the file descriptor 'fd' is an open file descriptor\n\\r
+connected to the slave end of a terminal.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_wait(PyObject *self, PyObject *noargs)\r
+posix_isatty(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
+    int fd;\r
+    if (!PyArg_ParseTuple(args, "i:isatty", &fd))\r
+        return NULL;\r
+    if (!_PyVerify_fd(fd))\r
+        return PyBool_FromLong(0);\r
+    return PyBool_FromLong(isatty(fd));\r
+}\r
+\r
+#ifdef HAVE_PIPE\r
+PyDoc_STRVAR(posix_pipe__doc__,\r
+"pipe() -> (read_end, write_end)\n\n\\r
+Create a pipe.");\r
 \r
 \r
+static PyObject *\r
+posix_pipe(PyObject *self, PyObject *noargs)\r
+{\r
+    int fds[2];\r
+    int res;\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    pid = wait(&status);\r
+    res = pipe(fds);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-    if (pid == -1)\r
+    if (res != 0)\r
         return posix_error();\r
         return posix_error();\r
-\r
-    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));\r
+    return Py_BuildValue("(ii)", fds[0], fds[1]);\r
 }\r
 }\r
-#endif\r
+#endif  /* HAVE_PIPE */\r
 \r
 \r
 \r
 \r
-PyDoc_STRVAR(posix_lstat__doc__,\r
-"lstat(path) -> stat result\n\n\\r
-Like stat(path), but do not follow symbolic links.");\r
+#ifdef HAVE_MKFIFO\r
+PyDoc_STRVAR(posix_mkfifo__doc__,\r
+"mkfifo(filename [, mode=0666])\n\n\\r
+Create a FIFO (a POSIX named pipe).");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_lstat(PyObject *self, PyObject *args)\r
+posix_mkfifo(PyObject *self, PyObject *args)\r
 {\r
 {\r
-#ifdef HAVE_LSTAT\r
-    return posix_do_stat(self, args, "et:lstat", lstat, NULL, NULL);\r
-#else /* !HAVE_LSTAT */\r
-    return posix_do_stat(self, args, "et:lstat", STAT, NULL, NULL);\r
-#endif /* !HAVE_LSTAT */\r
+    char *filename;\r
+    int mode = 0666;\r
+    int res;\r
+    if (!PyArg_ParseTuple(args, "s|i:mkfifo", &filename, &mode))\r
+        return NULL;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = mkfifo(filename, mode);\r
+    Py_END_ALLOW_THREADS\r
+    if (res < 0)\r
+        return posix_error();\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
 }\r
 }\r
+#endif\r
 \r
 \r
 \r
 \r
-#ifdef HAVE_READLINK\r
-PyDoc_STRVAR(posix_readlink__doc__,\r
-"readlink(path) -> path\n\n\\r
-Return a string representing the path to which the symbolic link points.");\r
+#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)\r
+PyDoc_STRVAR(posix_mknod__doc__,\r
+"mknod(filename [, mode=0600, device])\n\n\\r
+Create a filesystem node (file, device special file or named pipe)\n\\r
+named filename. mode specifies both the permissions to use and the\n\\r
+type of node to be created, being combined (bitwise OR) with one of\n\\r
+S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\\r
+device defines the newly created device special file (probably using\n\\r
+os.makedev()), otherwise it is ignored.");\r
+\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_readlink(PyObject *self, PyObject *args)\r
+posix_mknod(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject* v;\r
-    char buf[MAXPATHLEN];\r
-    char *path;\r
-    int n;\r
-#ifdef Py_USING_UNICODE\r
-    int arg_is_unicode = 0;\r
-#endif\r
-\r
-    if (!PyArg_ParseTuple(args, "et:readlink",\r
-                          Py_FileSystemDefaultEncoding, &path))\r
-        return NULL;\r
-#ifdef Py_USING_UNICODE\r
-    v = PySequence_GetItem(args, 0);\r
-    if (v == NULL) {\r
-        PyMem_Free(path);\r
+    char *filename;\r
+    int mode = 0600;\r
+    int device = 0;\r
+    int res;\r
+    if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))\r
         return NULL;\r
         return NULL;\r
-    }\r
-\r
-    if (PyUnicode_Check(v)) {\r
-        arg_is_unicode = 1;\r
-    }\r
-    Py_DECREF(v);\r
-#endif\r
-\r
     Py_BEGIN_ALLOW_THREADS\r
     Py_BEGIN_ALLOW_THREADS\r
-    n = readlink(path, buf, (int) sizeof buf);\r
+    res = mknod(filename, mode, device);\r
     Py_END_ALLOW_THREADS\r
     Py_END_ALLOW_THREADS\r
-    if (n < 0)\r
-        return posix_error_with_allocated_filename(path);\r
-\r
-    PyMem_Free(path);\r
-    v = PyString_FromStringAndSize(buf, n);\r
-#ifdef Py_USING_UNICODE\r
-    if (arg_is_unicode) {\r
-        PyObject *w;\r
-\r
-        w = PyUnicode_FromEncodedObject(v,\r
-                                        Py_FileSystemDefaultEncoding,\r
-                                        "strict");\r
-        if (w != NULL) {\r
-            Py_DECREF(v);\r
-            v = w;\r
-        }\r
-        else {\r
-            /* fall back to the original byte string, as\r
-               discussed in patch #683592 */\r
-            PyErr_Clear();\r
-        }\r
-    }\r
-#endif\r
-    return v;\r
+    if (res < 0)\r
+        return posix_error();\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
 }\r
 }\r
-#endif /* HAVE_READLINK */\r
-\r
+#endif\r
 \r
 \r
-#ifdef HAVE_SYMLINK\r
-PyDoc_STRVAR(posix_symlink__doc__,\r
-"symlink(src, dst)\n\n\\r
-Create a symbolic link pointing to src named dst.");\r
+#ifdef HAVE_DEVICE_MACROS\r
+PyDoc_STRVAR(posix_major__doc__,\r
+"major(device) -> major number\n\\r
+Extracts a device major number from a raw device number.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_symlink(PyObject *self, PyObject *args)\r
+posix_major(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    return posix_2str(args, "etet:symlink", symlink);\r
+    int device;\r
+    if (!PyArg_ParseTuple(args, "i:major", &device))\r
+        return NULL;\r
+    return PyInt_FromLong((long)major(device));\r
 }\r
 }\r
-#endif /* HAVE_SYMLINK */\r
-\r
-\r
-#ifdef HAVE_TIMES\r
-#if defined(PYCC_VACPP) && defined(PYOS_OS2)\r
-static long\r
-system_uptime(void)\r
-{\r
-    ULONG     value = 0;\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &value, sizeof(value));\r
-    Py_END_ALLOW_THREADS\r
 \r
 \r
-    return value;\r
-}\r
+PyDoc_STRVAR(posix_minor__doc__,\r
+"minor(device) -> minor number\n\\r
+Extracts a device minor number from a raw device number.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_times(PyObject *self, PyObject *noargs)\r
+posix_minor(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    /* Currently Only Uptime is Provided -- Others Later */\r
-    return Py_BuildValue("ddddd",\r
-                         (double)0 /* t.tms_utime / HZ */,\r
-                         (double)0 /* t.tms_stime / HZ */,\r
-                         (double)0 /* t.tms_cutime / HZ */,\r
-                         (double)0 /* t.tms_cstime / HZ */,\r
-                         (double)system_uptime() / 1000);\r
+    int device;\r
+    if (!PyArg_ParseTuple(args, "i:minor", &device))\r
+        return NULL;\r
+    return PyInt_FromLong((long)minor(device));\r
 }\r
 }\r
-#else /* not OS2 */\r
-#define NEED_TICKS_PER_SECOND\r
-static long ticks_per_second = -1;\r
+\r
+PyDoc_STRVAR(posix_makedev__doc__,\r
+"makedev(major, minor) -> device number\n\\r
+Composes a raw device number from the major and minor device numbers.");\r
+\r
 static PyObject *\r
 static PyObject *\r
-posix_times(PyObject *self, PyObject *noargs)\r
+posix_makedev(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    struct tms t;\r
-    clock_t c;\r
-    errno = 0;\r
-    c = times(&t);\r
-    if (c == (clock_t) -1)\r
-        return posix_error();\r
-    return Py_BuildValue("ddddd",\r
-                         (double)t.tms_utime / ticks_per_second,\r
-                         (double)t.tms_stime / ticks_per_second,\r
-                         (double)t.tms_cutime / ticks_per_second,\r
-                         (double)t.tms_cstime / ticks_per_second,\r
-                         (double)c / ticks_per_second);\r
+    int major, minor;\r
+    if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))\r
+        return NULL;\r
+    return PyInt_FromLong((long)makedev(major, minor));\r
 }\r
 }\r
-#endif /* not OS2 */\r
-#endif /* HAVE_TIMES */\r
+#endif /* device macros */\r
 \r
 \r
 \r
 \r
-#ifdef HAVE_TIMES\r
-PyDoc_STRVAR(posix_times__doc__,\r
-"times() -> (utime, stime, cutime, cstime, elapsed_time)\n\n\\r
-Return a tuple of floating point numbers indicating process times.");\r
-#endif\r
-\r
-\r
-#ifdef HAVE_GETSID\r
-PyDoc_STRVAR(posix_getsid__doc__,\r
-"getsid(pid) -> sid\n\n\\r
-Call the system call getsid().");\r
+#ifdef HAVE_FTRUNCATE\r
+PyDoc_STRVAR(posix_ftruncate__doc__,\r
+"ftruncate(fd, length)\n\n\\r
+Truncate a file to a specified length.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_getsid(PyObject *self, PyObject *args)\r
+posix_ftruncate(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    int sid;\r
-    if (!PyArg_ParseTuple(args, PARSE_PID ":getsid", &pid))\r
+    int fd;\r
+    off_t length;\r
+    int res;\r
+    PyObject *lenobj;\r
+\r
+    if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj))\r
         return NULL;\r
         return NULL;\r
-    sid = getsid(pid);\r
-    if (sid < 0)\r
+\r
+#if !defined(HAVE_LARGEFILE_SUPPORT)\r
+    length = PyInt_AsLong(lenobj);\r
+#else\r
+    length = PyLong_Check(lenobj) ?\r
+        PyLong_AsLongLong(lenobj) : PyInt_AsLong(lenobj);\r
+#endif\r
+    if (PyErr_Occurred())\r
+        return NULL;\r
+\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = ftruncate(fd, length);\r
+    Py_END_ALLOW_THREADS\r
+    if (res < 0)\r
         return posix_error();\r
         return posix_error();\r
-    return PyInt_FromLong((long)sid);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
 }\r
 }\r
-#endif /* HAVE_GETSID */\r
+#endif\r
 \r
 \r
+#ifdef HAVE_PUTENV\r
+PyDoc_STRVAR(posix_putenv__doc__,\r
+"putenv(key, value)\n\n\\r
+Change or add an environment variable.");\r
 \r
 \r
-#ifdef HAVE_SETSID\r
-PyDoc_STRVAR(posix_setsid__doc__,\r
-"setsid()\n\n\\r
-Call the system call setsid().");\r
+/* Save putenv() parameters as values here, so we can collect them when they\r
+ * get re-set with another call for the same key. */\r
+static PyObject *posix_putenv_garbage;\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setsid(PyObject *self, PyObject *noargs)\r
+posix_putenv(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    if (setsid() < 0)\r
-        return posix_error();\r
+    char *s1, *s2;\r
+    char *newenv;\r
+    PyObject *newstr;\r
+    size_t len;\r
+\r
+    if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))\r
+        return NULL;\r
+\r
+    /* XXX This can leak memory -- not easy to fix :-( */\r
+    len = strlen(s1) + strlen(s2) + 2;\r
+    /* len includes space for a trailing \0; the size arg to\r
+       PyString_FromStringAndSize does not count that */\r
+    newstr = PyString_FromStringAndSize(NULL, (int)len - 1);\r
+    if (newstr == NULL)\r
+        return PyErr_NoMemory();\r
+    newenv = PyString_AS_STRING(newstr);\r
+    PyOS_snprintf(newenv, len, "%s=%s", s1, s2);\r
+    if (putenv(newenv)) {\r
+        Py_DECREF(newstr);\r
+        posix_error();\r
+        return NULL;\r
+    }\r
+    /* Install the first arg and newstr in posix_putenv_garbage;\r
+     * this will cause previous value to be collected.  This has to\r
+     * happen after the real putenv() call because the old value\r
+     * was still accessible until then. */\r
+    if (PyDict_SetItem(posix_putenv_garbage,\r
+                       PyTuple_GET_ITEM(args, 0), newstr)) {\r
+        /* really not much we can do; just leak */\r
+        PyErr_Clear();\r
+    }\r
+    else {\r
+        Py_DECREF(newstr);\r
+    }\r
+\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
-#endif /* HAVE_SETSID */\r
+#endif /* putenv */\r
 \r
 \r
-#ifdef HAVE_SETPGID\r
-PyDoc_STRVAR(posix_setpgid__doc__,\r
-"setpgid(pid, pgrp)\n\n\\r
-Call the system call setpgid().");\r
+#ifdef HAVE_UNSETENV\r
+PyDoc_STRVAR(posix_unsetenv__doc__,\r
+"unsetenv(key)\n\n\\r
+Delete an environment variable.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_setpgid(PyObject *self, PyObject *args)\r
+posix_unsetenv(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    pid_t pid;\r
-    int pgrp;\r
-    if (!PyArg_ParseTuple(args, PARSE_PID "i:setpgid", &pid, &pgrp))\r
+    char *s1;\r
+\r
+    if (!PyArg_ParseTuple(args, "s:unsetenv", &s1))\r
         return NULL;\r
         return NULL;\r
-    if (setpgid(pid, pgrp) < 0)\r
-        return posix_error();\r
+\r
+    unsetenv(s1);\r
+\r
+    /* Remove the key from posix_putenv_garbage;\r
+     * this will cause it to be collected.  This has to\r
+     * happen after the real unsetenv() call because the\r
+     * old value was still accessible until then.\r
+     */\r
+    if (PyDict_DelItem(posix_putenv_garbage,\r
+                       PyTuple_GET_ITEM(args, 0))) {\r
+        /* really not much we can do; just leak */\r
+        PyErr_Clear();\r
+    }\r
+\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
     Py_INCREF(Py_None);\r
     return Py_None;\r
 }\r
-#endif /* HAVE_SETPGID */\r
-\r
+#endif /* unsetenv */\r
 \r
 \r
-#ifdef HAVE_TCGETPGRP\r
-PyDoc_STRVAR(posix_tcgetpgrp__doc__,\r
-"tcgetpgrp(fd) -> pgid\n\n\\r
-Return the process group associated with the terminal given by a fd.");\r
+PyDoc_STRVAR(posix_strerror__doc__,\r
+"strerror(code) -> string\n\n\\r
+Translate an error code to a message string.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_tcgetpgrp(PyObject *self, PyObject *args)\r
+posix_strerror(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int fd;\r
-    pid_t pgid;\r
-    if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd))\r
+    int code;\r
+    char *message;\r
+    if (!PyArg_ParseTuple(args, "i:strerror", &code))\r
         return NULL;\r
         return NULL;\r
-    pgid = tcgetpgrp(fd);\r
-    if (pgid < 0)\r
-        return posix_error();\r
-    return PyLong_FromPid(pgid);\r
+    message = strerror(code);\r
+    if (message == NULL) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "strerror() argument out of range");\r
+        return NULL;\r
+    }\r
+    return PyString_FromString(message);\r
 }\r
 }\r
-#endif /* HAVE_TCGETPGRP */\r
 \r
 \r
 \r
 \r
-#ifdef HAVE_TCSETPGRP\r
-PyDoc_STRVAR(posix_tcsetpgrp__doc__,\r
-"tcsetpgrp(fd, pgid)\n\n\\r
-Set the process group associated with the terminal given by a fd.");\r
+#ifdef HAVE_SYS_WAIT_H\r
+\r
+#ifdef WCOREDUMP\r
+PyDoc_STRVAR(posix_WCOREDUMP__doc__,\r
+"WCOREDUMP(status) -> bool\n\n\\r
+Return True if the process returning 'status' was dumped to a core file.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_tcsetpgrp(PyObject *self, PyObject *args)\r
+posix_WCOREDUMP(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int fd;\r
-    pid_t pgid;\r
-    if (!PyArg_ParseTuple(args, "i" PARSE_PID ":tcsetpgrp", &fd, &pgid))\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
+\r
+    if (!PyArg_ParseTuple(args, "i:WCOREDUMP", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
         return NULL;\r
-    if (tcsetpgrp(fd, pgid) < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif /* HAVE_TCSETPGRP */\r
 \r
 \r
-/* Functions acting on file descriptors */\r
+    return PyBool_FromLong(WCOREDUMP(status));\r
+}\r
+#endif /* WCOREDUMP */\r
 \r
 \r
-PyDoc_STRVAR(posix_open__doc__,\r
-"open(filename, flag [, mode=0777]) -> fd\n\n\\r
-Open a file (for low level IO).");\r
+#ifdef WIFCONTINUED\r
+PyDoc_STRVAR(posix_WIFCONTINUED__doc__,\r
+"WIFCONTINUED(status) -> bool\n\n\\r
+Return True if the process returning 'status' was continued from a\n\\r
+job control stop.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_open(PyObject *self, PyObject *args)\r
+posix_WIFCONTINUED(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    char *file = NULL;\r
-    int flag;\r
-    int mode = 0777;\r
-    int fd;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    if (!PyArg_ParseTuple(args, "eti|i",\r
-                          Py_FileSystemDefaultEncoding, &file,\r
-                          &flag, &mode))\r
+    if (!PyArg_ParseTuple(args, "i:WCONTINUED", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
 \r
         return NULL;\r
 \r
-    Py_BEGIN_ALLOW_THREADS\r
-    fd = open(file, flag, mode);\r
-    Py_END_ALLOW_THREADS\r
-    if (fd < 0)\r
-        return posix_error_with_allocated_filename(file);\r
-    PyMem_Free(file);\r
-    return PyInt_FromLong((long)fd);\r
+    return PyBool_FromLong(WIFCONTINUED(status));\r
 }\r
 }\r
+#endif /* WIFCONTINUED */\r
 \r
 \r
-\r
-PyDoc_STRVAR(posix_close__doc__,\r
-"close(fd)\n\n\\r
-Close a file descriptor (for low level IO).");\r
+#ifdef WIFSTOPPED\r
+PyDoc_STRVAR(posix_WIFSTOPPED__doc__,\r
+"WIFSTOPPED(status) -> bool\n\n\\r
+Return True if the process returning 'status' was stopped.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_close(PyObject *self, PyObject *args)\r
+posix_WIFSTOPPED(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int fd, res;\r
-    if (!PyArg_ParseTuple(args, "i:close", &fd))\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
+\r
+    if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
         return NULL;\r
-    if (!_PyVerify_fd(fd))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = close(fd);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
 \r
 \r
+    return PyBool_FromLong(WIFSTOPPED(status));\r
+}\r
+#endif /* WIFSTOPPED */\r
 \r
 \r
-PyDoc_STRVAR(posix_closerange__doc__,\r
-"closerange(fd_low, fd_high)\n\n\\r
-Closes all file descriptors in [fd_low, fd_high), ignoring errors.");\r
+#ifdef WIFSIGNALED\r
+PyDoc_STRVAR(posix_WIFSIGNALED__doc__,\r
+"WIFSIGNALED(status) -> bool\n\n\\r
+Return True if the process returning 'status' was terminated by a signal.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_closerange(PyObject *self, PyObject *args)\r
+posix_WIFSIGNALED(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int fd_from, fd_to, i;\r
-    if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    for (i = fd_from; i < fd_to; i++)\r
-        if (_PyVerify_fd(i))\r
-            close(i);\r
-    Py_END_ALLOW_THREADS\r
-    Py_RETURN_NONE;\r
-}\r
-\r
-\r
-PyDoc_STRVAR(posix_dup__doc__,\r
-"dup(fd) -> fd2\n\n\\r
-Return a duplicate of a file descriptor.");\r
-\r
-static PyObject *\r
-posix_dup(PyObject *self, PyObject *args)\r
-{\r
-    int fd;\r
-    if (!PyArg_ParseTuple(args, "i:dup", &fd))\r
-        return NULL;\r
-    if (!_PyVerify_fd(fd))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-    fd = dup(fd);\r
-    Py_END_ALLOW_THREADS\r
-    if (fd < 0)\r
-        return posix_error();\r
-    return PyInt_FromLong((long)fd);\r
-}\r
-\r
-\r
-PyDoc_STRVAR(posix_dup2__doc__,\r
-"dup2(old_fd, new_fd)\n\n\\r
-Duplicate file descriptor.");\r
-\r
-static PyObject *\r
-posix_dup2(PyObject *self, PyObject *args)\r
-{\r
-    int fd, fd2, res;\r
-    if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2))\r
-        return NULL;\r
-    if (!_PyVerify_fd_dup2(fd, fd2))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = dup2(fd, fd2);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-\r
-PyDoc_STRVAR(posix_lseek__doc__,\r
-"lseek(fd, pos, how) -> newpos\n\n\\r
-Set the current position of a file descriptor.");\r
-\r
-static PyObject *\r
-posix_lseek(PyObject *self, PyObject *args)\r
-{\r
-    int fd, how;\r
-    off_t pos, res;\r
-    PyObject *posobj;\r
-    if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))\r
-        return NULL;\r
-#ifdef SEEK_SET\r
-    /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */\r
-    switch (how) {\r
-    case 0: how = SEEK_SET; break;\r
-    case 1: how = SEEK_CUR; break;\r
-    case 2: how = SEEK_END; break;\r
-    }\r
-#endif /* SEEK_END */\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-#if !defined(HAVE_LARGEFILE_SUPPORT)\r
-    pos = PyInt_AsLong(posobj);\r
-#else\r
-    pos = PyLong_Check(posobj) ?\r
-        PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);\r
-#endif\r
-    if (PyErr_Occurred())\r
+    if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
 \r
         return NULL;\r
 \r
-    if (!_PyVerify_fd(fd))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = lseek(fd, pos, how);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-\r
-#if !defined(HAVE_LARGEFILE_SUPPORT)\r
-    return PyInt_FromLong(res);\r
-#else\r
-    return PyLong_FromLongLong(res);\r
-#endif\r
-}\r
-\r
-\r
-PyDoc_STRVAR(posix_read__doc__,\r
-"read(fd, buffersize) -> string\n\n\\r
-Read a file descriptor.");\r
-\r
-static PyObject *\r
-posix_read(PyObject *self, PyObject *args)\r
-{\r
-    int fd, size, n;\r
-    PyObject *buffer;\r
-    if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))\r
-        return NULL;\r
-    if (size < 0) {\r
-        errno = EINVAL;\r
-        return posix_error();\r
-    }\r
-    buffer = PyString_FromStringAndSize((char *)NULL, size);\r
-    if (buffer == NULL)\r
-        return NULL;\r
-    if (!_PyVerify_fd(fd)) {\r
-        Py_DECREF(buffer);\r
-        return posix_error();\r
-    }\r
-    Py_BEGIN_ALLOW_THREADS\r
-    n = read(fd, PyString_AsString(buffer), size);\r
-    Py_END_ALLOW_THREADS\r
-    if (n < 0) {\r
-        Py_DECREF(buffer);\r
-        return posix_error();\r
-    }\r
-    if (n != size)\r
-        _PyString_Resize(&buffer, n);\r
-    return buffer;\r
+    return PyBool_FromLong(WIFSIGNALED(status));\r
 }\r
 }\r
+#endif /* WIFSIGNALED */\r
 \r
 \r
-\r
-PyDoc_STRVAR(posix_write__doc__,\r
-"write(fd, string) -> byteswritten\n\n\\r
-Write a string to a file descriptor.");\r
+#ifdef WIFEXITED\r
+PyDoc_STRVAR(posix_WIFEXITED__doc__,\r
+"WIFEXITED(status) -> bool\n\n\\r
+Return true if the process returning 'status' exited using the exit()\n\\r
+system call.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_write(PyObject *self, PyObject *args)\r
+posix_WIFEXITED(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    Py_buffer pbuf;\r
-    int fd;\r
-    Py_ssize_t size;\r
-\r
-    if (!PyArg_ParseTuple(args, "is*:write", &fd, &pbuf))\r
-        return NULL;\r
-    if (!_PyVerify_fd(fd)) {\r
-        PyBuffer_Release(&pbuf);\r
-        return posix_error();\r
-    }\r
-    Py_BEGIN_ALLOW_THREADS\r
-    size = write(fd, pbuf.buf, (size_t)pbuf.len);\r
-    Py_END_ALLOW_THREADS\r
-    PyBuffer_Release(&pbuf);\r
-    if (size < 0)\r
-        return posix_error();\r
-    return PyInt_FromSsize_t(size);\r
-}\r
-\r
-\r
-PyDoc_STRVAR(posix_fstat__doc__,\r
-"fstat(fd) -> stat result\n\n\\r
-Like stat(), but for an open file descriptor.");\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-static PyObject *\r
-posix_fstat(PyObject *self, PyObject *args)\r
-{\r
-    int fd;\r
-    STRUCT_STAT st;\r
-    int res;\r
-    if (!PyArg_ParseTuple(args, "i:fstat", &fd))\r
+    if (!PyArg_ParseTuple(args, "i:WIFEXITED", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
         return NULL;\r
-    if (!_PyVerify_fd(fd))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = FSTAT(fd, &st);\r
-    Py_END_ALLOW_THREADS\r
-    if (res != 0) {\r
-      return posix_error();\r
-    }\r
 \r
 \r
-    return _pystat_fromstructstat(&st);\r
+    return PyBool_FromLong(WIFEXITED(status));\r
 }\r
 }\r
+#endif /* WIFEXITED */\r
 \r
 \r
-\r
-PyDoc_STRVAR(posix_fdopen__doc__,\r
-"fdopen(fd [, mode='r' [, bufsize]]) -> file_object\n\n\\r
-Return an open file object connected to a file descriptor.");\r
+#ifdef WEXITSTATUS\r
+PyDoc_STRVAR(posix_WEXITSTATUS__doc__,\r
+"WEXITSTATUS(status) -> integer\n\n\\r
+Return the process return code from 'status'.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_fdopen(PyObject *self, PyObject *args)\r
+posix_WEXITSTATUS(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    int fd;\r
-    char *orgmode = "r";\r
-    int bufsize = -1;\r
-    FILE *fp;\r
-    PyObject *f;\r
-    char *mode;\r
-    if (!PyArg_ParseTuple(args, "i|si", &fd, &orgmode, &bufsize))\r
-        return NULL;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    /* Sanitize mode.  See fileobject.c */\r
-    mode = PyMem_MALLOC(strlen(orgmode)+3);\r
-    if (!mode) {\r
-        PyErr_NoMemory();\r
-        return NULL;\r
-    }\r
-    strcpy(mode, orgmode);\r
-    if (_PyFile_SanitizeMode(mode)) {\r
-        PyMem_FREE(mode);\r
+    if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &WAIT_STATUS_INT(status)))\r
         return NULL;\r
         return NULL;\r
-    }\r
-    if (!_PyVerify_fd(fd))\r
-        return posix_error();\r
-    Py_BEGIN_ALLOW_THREADS\r
-#if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)\r
-    if (mode[0] == 'a') {\r
-        /* try to make sure the O_APPEND flag is set */\r
-        int flags;\r
-        flags = fcntl(fd, F_GETFL);\r
-        if (flags != -1)\r
-            fcntl(fd, F_SETFL, flags | O_APPEND);\r
-        fp = fdopen(fd, mode);\r
-        if (fp == NULL && flags != -1)\r
-            /* restore old mode if fdopen failed */\r
-            fcntl(fd, F_SETFL, flags);\r
-    } else {\r
-        fp = fdopen(fd, mode);\r
-    }\r
-#else\r
-    fp = fdopen(fd, mode);\r
-#endif\r
-    Py_END_ALLOW_THREADS\r
-    PyMem_FREE(mode);\r
-    if (fp == NULL)\r
-        return posix_error();\r
-    f = PyFile_FromFile(fp, "<fdopen>", orgmode, fclose);\r
-    if (f != NULL)\r
-        PyFile_SetBufSize(f, bufsize);\r
-    return f;\r
-}\r
-\r
-PyDoc_STRVAR(posix_isatty__doc__,\r
-"isatty(fd) -> bool\n\n\\r
-Return True if the file descriptor 'fd' is an open file descriptor\n\\r
-connected to the slave end of a terminal.");\r
 \r
 \r
-static PyObject *\r
-posix_isatty(PyObject *self, PyObject *args)\r
-{\r
-    int fd;\r
-    if (!PyArg_ParseTuple(args, "i:isatty", &fd))\r
-        return NULL;\r
-    if (!_PyVerify_fd(fd))\r
-        return PyBool_FromLong(0);\r
-    return PyBool_FromLong(isatty(fd));\r
-}\r
-\r
-#ifdef HAVE_PIPE\r
-PyDoc_STRVAR(posix_pipe__doc__,\r
-"pipe() -> (read_end, write_end)\n\n\\r
-Create a pipe.");\r
-\r
-static PyObject *\r
-posix_pipe(PyObject *self, PyObject *noargs)\r
-{\r
-#if defined(PYOS_OS2)\r
-    HFILE read, write;\r
-    APIRET rc;\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    rc = DosCreatePipe( &read, &write, 4096);\r
-    Py_END_ALLOW_THREADS\r
-    if (rc != NO_ERROR)\r
-        return os2_error(rc);\r
-\r
-    return Py_BuildValue("(ii)", read, write);\r
-#else\r
-#if !defined(MS_WINDOWS)\r
-    int fds[2];\r
-    int res;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = pipe(fds);\r
-    Py_END_ALLOW_THREADS\r
-    if (res != 0)\r
-        return posix_error();\r
-    return Py_BuildValue("(ii)", fds[0], fds[1]);\r
-#else /* MS_WINDOWS */\r
-    HANDLE read, write;\r
-    int read_fd, write_fd;\r
-    BOOL ok;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    ok = CreatePipe(&read, &write, NULL, 0);\r
-    Py_END_ALLOW_THREADS\r
-    if (!ok)\r
-        return win32_error("CreatePipe", NULL);\r
-    read_fd = _open_osfhandle((Py_intptr_t)read, 0);\r
-    write_fd = _open_osfhandle((Py_intptr_t)write, 1);\r
-    return Py_BuildValue("(ii)", read_fd, write_fd);\r
-#endif /* MS_WINDOWS */\r
-#endif\r
-}\r
-#endif  /* HAVE_PIPE */\r
-\r
-\r
-#ifdef HAVE_MKFIFO\r
-PyDoc_STRVAR(posix_mkfifo__doc__,\r
-"mkfifo(filename [, mode=0666])\n\n\\r
-Create a FIFO (a POSIX named pipe).");\r
-\r
-static PyObject *\r
-posix_mkfifo(PyObject *self, PyObject *args)\r
-{\r
-    char *filename;\r
-    int mode = 0666;\r
-    int res;\r
-    if (!PyArg_ParseTuple(args, "s|i:mkfifo", &filename, &mode))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = mkfifo(filename, mode);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif\r
-\r
-\r
-#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)\r
-PyDoc_STRVAR(posix_mknod__doc__,\r
-"mknod(filename [, mode=0600, device])\n\n\\r
-Create a filesystem node (file, device special file or named pipe)\n\\r
-named filename. mode specifies both the permissions to use and the\n\\r
-type of node to be created, being combined (bitwise OR) with one of\n\\r
-S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\\r
-device defines the newly created device special file (probably using\n\\r
-os.makedev()), otherwise it is ignored.");\r
-\r
-\r
-static PyObject *\r
-posix_mknod(PyObject *self, PyObject *args)\r
-{\r
-    char *filename;\r
-    int mode = 0600;\r
-    int device = 0;\r
-    int res;\r
-    if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = mknod(filename, mode, device);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_DEVICE_MACROS\r
-PyDoc_STRVAR(posix_major__doc__,\r
-"major(device) -> major number\n\\r
-Extracts a device major number from a raw device number.");\r
-\r
-static PyObject *\r
-posix_major(PyObject *self, PyObject *args)\r
-{\r
-    int device;\r
-    if (!PyArg_ParseTuple(args, "i:major", &device))\r
-        return NULL;\r
-    return PyInt_FromLong((long)major(device));\r
-}\r
-\r
-PyDoc_STRVAR(posix_minor__doc__,\r
-"minor(device) -> minor number\n\\r
-Extracts a device minor number from a raw device number.");\r
-\r
-static PyObject *\r
-posix_minor(PyObject *self, PyObject *args)\r
-{\r
-    int device;\r
-    if (!PyArg_ParseTuple(args, "i:minor", &device))\r
-        return NULL;\r
-    return PyInt_FromLong((long)minor(device));\r
-}\r
-\r
-PyDoc_STRVAR(posix_makedev__doc__,\r
-"makedev(major, minor) -> device number\n\\r
-Composes a raw device number from the major and minor device numbers.");\r
-\r
-static PyObject *\r
-posix_makedev(PyObject *self, PyObject *args)\r
-{\r
-    int major, minor;\r
-    if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))\r
-        return NULL;\r
-    return PyInt_FromLong((long)makedev(major, minor));\r
-}\r
-#endif /* device macros */\r
-\r
-\r
-#ifdef HAVE_FTRUNCATE\r
-PyDoc_STRVAR(posix_ftruncate__doc__,\r
-"ftruncate(fd, length)\n\n\\r
-Truncate a file to a specified length.");\r
-\r
-static PyObject *\r
-posix_ftruncate(PyObject *self, PyObject *args)\r
-{\r
-    int fd;\r
-    off_t length;\r
-    int res;\r
-    PyObject *lenobj;\r
-\r
-    if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj))\r
-        return NULL;\r
-\r
-#if !defined(HAVE_LARGEFILE_SUPPORT)\r
-    length = PyInt_AsLong(lenobj);\r
-#else\r
-    length = PyLong_Check(lenobj) ?\r
-        PyLong_AsLongLong(lenobj) : PyInt_AsLong(lenobj);\r
-#endif\r
-    if (PyErr_Occurred())\r
-        return NULL;\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = ftruncate(fd, length);\r
-    Py_END_ALLOW_THREADS\r
-    if (res < 0)\r
-        return posix_error();\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_PUTENV\r
-PyDoc_STRVAR(posix_putenv__doc__,\r
-"putenv(key, value)\n\n\\r
-Change or add an environment variable.");\r
-\r
-/* Save putenv() parameters as values here, so we can collect them when they\r
- * get re-set with another call for the same key. */\r
-static PyObject *posix_putenv_garbage;\r
-\r
-static PyObject *\r
-posix_putenv(PyObject *self, PyObject *args)\r
-{\r
-    char *s1, *s2;\r
-    char *newenv;\r
-    PyObject *newstr;\r
-    size_t len;\r
-\r
-    if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))\r
-        return NULL;\r
-\r
-#if defined(PYOS_OS2)\r
-    if (stricmp(s1, "BEGINLIBPATH") == 0) {\r
-        APIRET rc;\r
-\r
-        rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);\r
-        if (rc != NO_ERROR)\r
-            return os2_error(rc);\r
-\r
-    } else if (stricmp(s1, "ENDLIBPATH") == 0) {\r
-        APIRET rc;\r
-\r
-        rc = DosSetExtLIBPATH(s2, END_LIBPATH);\r
-        if (rc != NO_ERROR)\r
-            return os2_error(rc);\r
-    } else {\r
-#endif\r
-\r
-    /* XXX This can leak memory -- not easy to fix :-( */\r
-    len = strlen(s1) + strlen(s2) + 2;\r
-    /* len includes space for a trailing \0; the size arg to\r
-       PyString_FromStringAndSize does not count that */\r
-    newstr = PyString_FromStringAndSize(NULL, (int)len - 1);\r
-    if (newstr == NULL)\r
-        return PyErr_NoMemory();\r
-    newenv = PyString_AS_STRING(newstr);\r
-    PyOS_snprintf(newenv, len, "%s=%s", s1, s2);\r
-    if (putenv(newenv)) {\r
-        Py_DECREF(newstr);\r
-        posix_error();\r
-        return NULL;\r
-    }\r
-    /* Install the first arg and newstr in posix_putenv_garbage;\r
-     * this will cause previous value to be collected.  This has to\r
-     * happen after the real putenv() call because the old value\r
-     * was still accessible until then. */\r
-    if (PyDict_SetItem(posix_putenv_garbage,\r
-                       PyTuple_GET_ITEM(args, 0), newstr)) {\r
-        /* really not much we can do; just leak */\r
-        PyErr_Clear();\r
-    }\r
-    else {\r
-        Py_DECREF(newstr);\r
-    }\r
-\r
-#if defined(PYOS_OS2)\r
-    }\r
-#endif\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif /* putenv */\r
-\r
-#ifdef HAVE_UNSETENV\r
-PyDoc_STRVAR(posix_unsetenv__doc__,\r
-"unsetenv(key)\n\n\\r
-Delete an environment variable.");\r
-\r
-static PyObject *\r
-posix_unsetenv(PyObject *self, PyObject *args)\r
-{\r
-    char *s1;\r
-\r
-    if (!PyArg_ParseTuple(args, "s:unsetenv", &s1))\r
-        return NULL;\r
-\r
-    unsetenv(s1);\r
-\r
-    /* Remove the key from posix_putenv_garbage;\r
-     * this will cause it to be collected.  This has to\r
-     * happen after the real unsetenv() call because the\r
-     * old value was still accessible until then.\r
-     */\r
-    if (PyDict_DelItem(posix_putenv_garbage,\r
-                       PyTuple_GET_ITEM(args, 0))) {\r
-        /* really not much we can do; just leak */\r
-        PyErr_Clear();\r
-    }\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-#endif /* unsetenv */\r
-\r
-PyDoc_STRVAR(posix_strerror__doc__,\r
-"strerror(code) -> string\n\n\\r
-Translate an error code to a message string.");\r
-\r
-static PyObject *\r
-posix_strerror(PyObject *self, PyObject *args)\r
-{\r
-    int code;\r
-    char *message;\r
-    if (!PyArg_ParseTuple(args, "i:strerror", &code))\r
-        return NULL;\r
-    message = strerror(code);\r
-    if (message == NULL) {\r
-        PyErr_SetString(PyExc_ValueError,\r
-                        "strerror() argument out of range");\r
-        return NULL;\r
-    }\r
-    return PyString_FromString(message);\r
-}\r
-\r
-\r
-#ifdef HAVE_SYS_WAIT_H\r
-\r
-#ifdef WCOREDUMP\r
-PyDoc_STRVAR(posix_WCOREDUMP__doc__,\r
-"WCOREDUMP(status) -> bool\n\n\\r
-Return True if the process returning 'status' was dumped to a core file.");\r
-\r
-static PyObject *\r
-posix_WCOREDUMP(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WCOREDUMP", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return PyBool_FromLong(WCOREDUMP(status));\r
-}\r
-#endif /* WCOREDUMP */\r
-\r
-#ifdef WIFCONTINUED\r
-PyDoc_STRVAR(posix_WIFCONTINUED__doc__,\r
-"WIFCONTINUED(status) -> bool\n\n\\r
-Return True if the process returning 'status' was continued from a\n\\r
-job control stop.");\r
-\r
-static PyObject *\r
-posix_WIFCONTINUED(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WCONTINUED", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return PyBool_FromLong(WIFCONTINUED(status));\r
-}\r
-#endif /* WIFCONTINUED */\r
-\r
-#ifdef WIFSTOPPED\r
-PyDoc_STRVAR(posix_WIFSTOPPED__doc__,\r
-"WIFSTOPPED(status) -> bool\n\n\\r
-Return True if the process returning 'status' was stopped.");\r
-\r
-static PyObject *\r
-posix_WIFSTOPPED(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return PyBool_FromLong(WIFSTOPPED(status));\r
-}\r
-#endif /* WIFSTOPPED */\r
-\r
-#ifdef WIFSIGNALED\r
-PyDoc_STRVAR(posix_WIFSIGNALED__doc__,\r
-"WIFSIGNALED(status) -> bool\n\n\\r
-Return True if the process returning 'status' was terminated by a signal.");\r
-\r
-static PyObject *\r
-posix_WIFSIGNALED(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return PyBool_FromLong(WIFSIGNALED(status));\r
-}\r
-#endif /* WIFSIGNALED */\r
-\r
-#ifdef WIFEXITED\r
-PyDoc_STRVAR(posix_WIFEXITED__doc__,\r
-"WIFEXITED(status) -> bool\n\n\\r
-Return true if the process returning 'status' exited using the exit()\n\\r
-system call.");\r
-\r
-static PyObject *\r
-posix_WIFEXITED(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WIFEXITED", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return PyBool_FromLong(WIFEXITED(status));\r
-}\r
-#endif /* WIFEXITED */\r
-\r
-#ifdef WEXITSTATUS\r
-PyDoc_STRVAR(posix_WEXITSTATUS__doc__,\r
-"WEXITSTATUS(status) -> integer\n\n\\r
-Return the process return code from 'status'.");\r
-\r
-static PyObject *\r
-posix_WEXITSTATUS(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return Py_BuildValue("i", WEXITSTATUS(status));\r
-}\r
-#endif /* WEXITSTATUS */\r
-\r
-#ifdef WTERMSIG\r
-PyDoc_STRVAR(posix_WTERMSIG__doc__,\r
-"WTERMSIG(status) -> integer\n\n\\r
-Return the signal that terminated the process that provided the 'status'\n\\r
-value.");\r
-\r
-static PyObject *\r
-posix_WTERMSIG(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WTERMSIG", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return Py_BuildValue("i", WTERMSIG(status));\r
-}\r
-#endif /* WTERMSIG */\r
-\r
-#ifdef WSTOPSIG\r
-PyDoc_STRVAR(posix_WSTOPSIG__doc__,\r
-"WSTOPSIG(status) -> integer\n\n\\r
-Return the signal that stopped the process that provided\n\\r
-the 'status' value.");\r
-\r
-static PyObject *\r
-posix_WSTOPSIG(PyObject *self, PyObject *args)\r
-{\r
-    WAIT_TYPE status;\r
-    WAIT_STATUS_INT(status) = 0;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &WAIT_STATUS_INT(status)))\r
-        return NULL;\r
-\r
-    return Py_BuildValue("i", WSTOPSIG(status));\r
-}\r
-#endif /* WSTOPSIG */\r
-\r
-#endif /* HAVE_SYS_WAIT_H */\r
-\r
-\r
-#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)\r
-#ifdef _SCO_DS\r
-/* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the\r
-   needed definitions in sys/statvfs.h */\r
-#define _SVID3\r
-#endif\r
-#include <sys/statvfs.h>\r
-\r
-static PyObject*\r
-_pystatvfs_fromstructstatvfs(struct statvfs st) {\r
-    PyObject *v = PyStructSequence_New(&StatVFSResultType);\r
-    if (v == NULL)\r
-        return NULL;\r
-\r
-#if !defined(HAVE_LARGEFILE_SUPPORT)\r
-    PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));\r
-    PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));\r
-    PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) st.f_blocks));\r
-    PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) st.f_bfree));\r
-    PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) st.f_bavail));\r
-    PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) st.f_files));\r
-    PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long) st.f_ffree));\r
-    PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) st.f_favail));\r
-    PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));\r
-    PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));\r
-#else\r
-    PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));\r
-    PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));\r
-    PyStructSequence_SET_ITEM(v, 2,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));\r
-    PyStructSequence_SET_ITEM(v, 3,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));\r
-    PyStructSequence_SET_ITEM(v, 4,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));\r
-    PyStructSequence_SET_ITEM(v, 5,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_files));\r
-    PyStructSequence_SET_ITEM(v, 6,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));\r
-    PyStructSequence_SET_ITEM(v, 7,\r
-                              PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));\r
-    PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));\r
-    PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));\r
-#endif\r
-\r
-    return v;\r
-}\r
-\r
-PyDoc_STRVAR(posix_fstatvfs__doc__,\r
-"fstatvfs(fd) -> statvfs result\n\n\\r
-Perform an fstatvfs system call on the given fd.");\r
-\r
-static PyObject *\r
-posix_fstatvfs(PyObject *self, PyObject *args)\r
-{\r
-    int fd, res;\r
-    struct statvfs st;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = fstatvfs(fd, &st);\r
-    Py_END_ALLOW_THREADS\r
-    if (res != 0)\r
-        return posix_error();\r
-\r
-    return _pystatvfs_fromstructstatvfs(st);\r
-}\r
-#endif /* HAVE_FSTATVFS && HAVE_SYS_STATVFS_H */\r
-\r
-\r
-#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)\r
-#include <sys/statvfs.h>\r
-\r
-PyDoc_STRVAR(posix_statvfs__doc__,\r
-"statvfs(path) -> statvfs result\n\n\\r
-Perform a statvfs system call on the given path.");\r
-\r
-static PyObject *\r
-posix_statvfs(PyObject *self, PyObject *args)\r
-{\r
-    char *path;\r
-    int res;\r
-    struct statvfs st;\r
-    if (!PyArg_ParseTuple(args, "s:statvfs", &path))\r
-        return NULL;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    res = statvfs(path, &st);\r
-    Py_END_ALLOW_THREADS\r
-    if (res != 0)\r
-        return posix_error_with_filename(path);\r
-\r
-    return _pystatvfs_fromstructstatvfs(st);\r
-}\r
-#endif /* HAVE_STATVFS */\r
-\r
-\r
-#ifdef HAVE_TEMPNAM\r
-PyDoc_STRVAR(posix_tempnam__doc__,\r
-"tempnam([dir[, prefix]]) -> string\n\n\\r
-Return a unique name for a temporary file.\n\\r
-The directory and a prefix may be specified as strings; they may be omitted\n\\r
-or None if not needed.");\r
-\r
-static PyObject *\r
-posix_tempnam(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *result = NULL;\r
-    char *dir = NULL;\r
-    char *pfx = NULL;\r
-    char *name;\r
-\r
-    if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx))\r
-    return NULL;\r
-\r
-    if (PyErr_Warn(PyExc_RuntimeWarning,\r
-                   "tempnam is a potential security risk to your program") < 0)\r
-        return NULL;\r
-\r
-    if (PyErr_WarnPy3k("tempnam has been removed in 3.x; "\r
-                       "use the tempfile module", 1) < 0)\r
-        return NULL;\r
-\r
-    name = tempnam(dir, pfx);\r
-    if (name == NULL)\r
-        return PyErr_NoMemory();\r
-    result = PyString_FromString(name);\r
-    free(name);\r
-    return result;\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_TMPFILE\r
-PyDoc_STRVAR(posix_tmpfile__doc__,\r
-"tmpfile() -> file object\n\n\\r
-Create a temporary file with no directory entries.");\r
-\r
-static PyObject *\r
-posix_tmpfile(PyObject *self, PyObject *noargs)\r
-{\r
-    FILE *fp;\r
-\r
-    if (PyErr_WarnPy3k("tmpfile has been removed in 3.x; "\r
-                       "use the tempfile module", 1) < 0)\r
-        return NULL;\r
-\r
-    fp = tmpfile();\r
-    if (fp == NULL)\r
-        return posix_error();\r
-    return PyFile_FromFile(fp, "<tmpfile>", "w+b", fclose);\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_TMPNAM\r
-PyDoc_STRVAR(posix_tmpnam__doc__,\r
-"tmpnam() -> string\n\n\\r
-Return a unique name for a temporary file.");\r
-\r
-static PyObject *\r
-posix_tmpnam(PyObject *self, PyObject *noargs)\r
-{\r
-    char buffer[L_tmpnam];\r
-    char *name;\r
-\r
-    if (PyErr_Warn(PyExc_RuntimeWarning,\r
-                   "tmpnam is a potential security risk to your program") < 0)\r
-        return NULL;\r
-\r
-    if (PyErr_WarnPy3k("tmpnam has been removed in 3.x; "\r
-                       "use the tempfile module", 1) < 0)\r
-        return NULL;\r
-\r
-#ifdef USE_TMPNAM_R\r
-    name = tmpnam_r(buffer);\r
-#else\r
-    name = tmpnam(buffer);\r
-#endif\r
-    if (name == NULL) {\r
-        PyObject *err = Py_BuildValue("is", 0,\r
-#ifdef USE_TMPNAM_R\r
-                                      "unexpected NULL from tmpnam_r"\r
-#else\r
-                                      "unexpected NULL from tmpnam"\r
-#endif\r
-                                      );\r
-        PyErr_SetObject(PyExc_OSError, err);\r
-        Py_XDECREF(err);\r
-        return NULL;\r
-    }\r
-    return PyString_FromString(buffer);\r
-}\r
-#endif\r
-\r
-\r
-/* This is used for fpathconf(), pathconf(), confstr() and sysconf().\r
- * It maps strings representing configuration variable names to\r
- * integer values, allowing those functions to be called with the\r
- * magic names instead of polluting the module's namespace with tons of\r
- * rarely-used constants.  There are three separate tables that use\r
- * these definitions.\r
- *\r
- * This code is always included, even if none of the interfaces that\r
- * need it are included.  The #if hackery needed to avoid it would be\r
- * sufficiently pervasive that it's not worth the loss of readability.\r
- */\r
-struct constdef {\r
-    char *name;\r
-    long value;\r
-};\r
-\r
-#ifndef UEFI_C_SOURCE\r
-static int\r
-conv_confname(PyObject *arg, int *valuep, struct constdef *table,\r
-              size_t tablesize)\r
-{\r
-    if (PyInt_Check(arg)) {\r
-        *valuep = PyInt_AS_LONG(arg);\r
-        return 1;\r
-    }\r
-    if (PyString_Check(arg)) {\r
-        /* look up the value in the table using a binary search */\r
-        size_t lo = 0;\r
-        size_t mid;\r
-        size_t hi = tablesize;\r
-        int cmp;\r
-        char *confname = PyString_AS_STRING(arg);\r
-        while (lo < hi) {\r
-            mid = (lo + hi) / 2;\r
-            cmp = strcmp(confname, table[mid].name);\r
-            if (cmp < 0)\r
-                hi = mid;\r
-            else if (cmp > 0)\r
-                lo = mid + 1;\r
-            else {\r
-                *valuep = table[mid].value;\r
-                return 1;\r
-            }\r
-        }\r
-        PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");\r
-    }\r
-    else\r
-        PyErr_SetString(PyExc_TypeError,\r
-                        "configuration names must be strings or integers");\r
-    return 0;\r
-}\r
-#endif  /* UEFI_C_SOURCE */\r
-\r
-#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)\r
-static struct constdef  posix_constants_pathconf[] = {\r
-#ifdef _PC_ABI_AIO_XFER_MAX\r
-    {"PC_ABI_AIO_XFER_MAX",     _PC_ABI_AIO_XFER_MAX},\r
-#endif\r
-#ifdef _PC_ABI_ASYNC_IO\r
-    {"PC_ABI_ASYNC_IO", _PC_ABI_ASYNC_IO},\r
-#endif\r
-#ifdef _PC_ASYNC_IO\r
-    {"PC_ASYNC_IO",     _PC_ASYNC_IO},\r
-#endif\r
-#ifdef _PC_CHOWN_RESTRICTED\r
-    {"PC_CHOWN_RESTRICTED",     _PC_CHOWN_RESTRICTED},\r
-#endif\r
-#ifdef _PC_FILESIZEBITS\r
-    {"PC_FILESIZEBITS", _PC_FILESIZEBITS},\r
-#endif\r
-#ifdef _PC_LAST\r
-    {"PC_LAST", _PC_LAST},\r
-#endif\r
-#ifdef _PC_LINK_MAX\r
-    {"PC_LINK_MAX",     _PC_LINK_MAX},\r
-#endif\r
-#ifdef _PC_MAX_CANON\r
-    {"PC_MAX_CANON",    _PC_MAX_CANON},\r
-#endif\r
-#ifdef _PC_MAX_INPUT\r
-    {"PC_MAX_INPUT",    _PC_MAX_INPUT},\r
-#endif\r
-#ifdef _PC_NAME_MAX\r
-    {"PC_NAME_MAX",     _PC_NAME_MAX},\r
-#endif\r
-#ifdef _PC_NO_TRUNC\r
-    {"PC_NO_TRUNC",     _PC_NO_TRUNC},\r
-#endif\r
-#ifdef _PC_PATH_MAX\r
-    {"PC_PATH_MAX",     _PC_PATH_MAX},\r
-#endif\r
-#ifdef _PC_PIPE_BUF\r
-    {"PC_PIPE_BUF",     _PC_PIPE_BUF},\r
-#endif\r
-#ifdef _PC_PRIO_IO\r
-    {"PC_PRIO_IO",      _PC_PRIO_IO},\r
-#endif\r
-#ifdef _PC_SOCK_MAXBUF\r
-    {"PC_SOCK_MAXBUF",  _PC_SOCK_MAXBUF},\r
-#endif\r
-#ifdef _PC_SYNC_IO\r
-    {"PC_SYNC_IO",      _PC_SYNC_IO},\r
-#endif\r
-#ifdef _PC_VDISABLE\r
-    {"PC_VDISABLE",     _PC_VDISABLE},\r
-#endif\r
-};\r
-\r
-static int\r
-conv_path_confname(PyObject *arg, int *valuep)\r
-{\r
-    return conv_confname(arg, valuep, posix_constants_pathconf,\r
-                         sizeof(posix_constants_pathconf)\r
-                           / sizeof(struct constdef));\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_FPATHCONF\r
-PyDoc_STRVAR(posix_fpathconf__doc__,\r
-"fpathconf(fd, name) -> integer\n\n\\r
-Return the configuration limit name for the file descriptor fd.\n\\r
-If there is no limit, return -1.");\r
-\r
-static PyObject *\r
-posix_fpathconf(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *result = NULL;\r
-    int name, fd;\r
-\r
-    if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd,\r
-                         conv_path_confname, &name)) {\r
-        long limit;\r
-\r
-        errno = 0;\r
-        limit = fpathconf(fd, name);\r
-        if (limit == -1 && errno != 0)\r
-            posix_error();\r
-        else\r
-            result = PyInt_FromLong(limit);\r
-    }\r
-    return result;\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_PATHCONF\r
-PyDoc_STRVAR(posix_pathconf__doc__,\r
-"pathconf(path, name) -> integer\n\n\\r
-Return the configuration limit name for the file or directory path.\n\\r
-If there is no limit, return -1.");\r
-\r
-static PyObject *\r
-posix_pathconf(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *result = NULL;\r
-    int name;\r
-    char *path;\r
-\r
-    if (PyArg_ParseTuple(args, "sO&:pathconf", &path,\r
-                         conv_path_confname, &name)) {\r
-    long limit;\r
-\r
-    errno = 0;\r
-    limit = pathconf(path, name);\r
-    if (limit == -1 && errno != 0) {\r
-        if (errno == EINVAL)\r
-            /* could be a path or name problem */\r
-            posix_error();\r
-        else\r
-            posix_error_with_filename(path);\r
-    }\r
-    else\r
-        result = PyInt_FromLong(limit);\r
-    }\r
-    return result;\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_CONFSTR\r
-static struct constdef posix_constants_confstr[] = {\r
-#ifdef _CS_ARCHITECTURE\r
-    {"CS_ARCHITECTURE", _CS_ARCHITECTURE},\r
-#endif\r
-#ifdef _CS_HOSTNAME\r
-    {"CS_HOSTNAME",     _CS_HOSTNAME},\r
-#endif\r
-#ifdef _CS_HW_PROVIDER\r
-    {"CS_HW_PROVIDER",  _CS_HW_PROVIDER},\r
-#endif\r
-#ifdef _CS_HW_SERIAL\r
-    {"CS_HW_SERIAL",    _CS_HW_SERIAL},\r
-#endif\r
-#ifdef _CS_INITTAB_NAME\r
-    {"CS_INITTAB_NAME", _CS_INITTAB_NAME},\r
-#endif\r
-#ifdef _CS_LFS64_CFLAGS\r
-    {"CS_LFS64_CFLAGS", _CS_LFS64_CFLAGS},\r
-#endif\r
-#ifdef _CS_LFS64_LDFLAGS\r
-    {"CS_LFS64_LDFLAGS",        _CS_LFS64_LDFLAGS},\r
-#endif\r
-#ifdef _CS_LFS64_LIBS\r
-    {"CS_LFS64_LIBS",   _CS_LFS64_LIBS},\r
-#endif\r
-#ifdef _CS_LFS64_LINTFLAGS\r
-    {"CS_LFS64_LINTFLAGS",      _CS_LFS64_LINTFLAGS},\r
-#endif\r
-#ifdef _CS_LFS_CFLAGS\r
-    {"CS_LFS_CFLAGS",   _CS_LFS_CFLAGS},\r
-#endif\r
-#ifdef _CS_LFS_LDFLAGS\r
-    {"CS_LFS_LDFLAGS",  _CS_LFS_LDFLAGS},\r
-#endif\r
-#ifdef _CS_LFS_LIBS\r
-    {"CS_LFS_LIBS",     _CS_LFS_LIBS},\r
-#endif\r
-#ifdef _CS_LFS_LINTFLAGS\r
-    {"CS_LFS_LINTFLAGS",        _CS_LFS_LINTFLAGS},\r
-#endif\r
-#ifdef _CS_MACHINE\r
-    {"CS_MACHINE",      _CS_MACHINE},\r
-#endif\r
-#ifdef _CS_PATH\r
-    {"CS_PATH", _CS_PATH},\r
-#endif\r
-#ifdef _CS_RELEASE\r
-    {"CS_RELEASE",      _CS_RELEASE},\r
-#endif\r
-#ifdef _CS_SRPC_DOMAIN\r
-    {"CS_SRPC_DOMAIN",  _CS_SRPC_DOMAIN},\r
-#endif\r
-#ifdef _CS_SYSNAME\r
-    {"CS_SYSNAME",      _CS_SYSNAME},\r
-#endif\r
-#ifdef _CS_VERSION\r
-    {"CS_VERSION",      _CS_VERSION},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFF32_CFLAGS\r
-    {"CS_XBS5_ILP32_OFF32_CFLAGS",      _CS_XBS5_ILP32_OFF32_CFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS\r
-    {"CS_XBS5_ILP32_OFF32_LDFLAGS",     _CS_XBS5_ILP32_OFF32_LDFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFF32_LIBS\r
-    {"CS_XBS5_ILP32_OFF32_LIBS",        _CS_XBS5_ILP32_OFF32_LIBS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS\r
-    {"CS_XBS5_ILP32_OFF32_LINTFLAGS",   _CS_XBS5_ILP32_OFF32_LINTFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS\r
-    {"CS_XBS5_ILP32_OFFBIG_CFLAGS",     _CS_XBS5_ILP32_OFFBIG_CFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS\r
-    {"CS_XBS5_ILP32_OFFBIG_LDFLAGS",    _CS_XBS5_ILP32_OFFBIG_LDFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFFBIG_LIBS\r
-    {"CS_XBS5_ILP32_OFFBIG_LIBS",       _CS_XBS5_ILP32_OFFBIG_LIBS},\r
-#endif\r
-#ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS\r
-    {"CS_XBS5_ILP32_OFFBIG_LINTFLAGS",  _CS_XBS5_ILP32_OFFBIG_LINTFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LP64_OFF64_CFLAGS\r
-    {"CS_XBS5_LP64_OFF64_CFLAGS",       _CS_XBS5_LP64_OFF64_CFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LP64_OFF64_LDFLAGS\r
-    {"CS_XBS5_LP64_OFF64_LDFLAGS",      _CS_XBS5_LP64_OFF64_LDFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LP64_OFF64_LIBS\r
-    {"CS_XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS},\r
-#endif\r
-#ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS\r
-    {"CS_XBS5_LP64_OFF64_LINTFLAGS",    _CS_XBS5_LP64_OFF64_LINTFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS\r
-    {"CS_XBS5_LPBIG_OFFBIG_CFLAGS",     _CS_XBS5_LPBIG_OFFBIG_CFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS\r
-    {"CS_XBS5_LPBIG_OFFBIG_LDFLAGS",    _CS_XBS5_LPBIG_OFFBIG_LDFLAGS},\r
-#endif\r
-#ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS\r
-    {"CS_XBS5_LPBIG_OFFBIG_LIBS",       _CS_XBS5_LPBIG_OFFBIG_LIBS},\r
-#endif\r
-#ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS\r
-    {"CS_XBS5_LPBIG_OFFBIG_LINTFLAGS",  _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS},\r
-#endif\r
-#ifdef _MIPS_CS_AVAIL_PROCESSORS\r
-    {"MIPS_CS_AVAIL_PROCESSORS",        _MIPS_CS_AVAIL_PROCESSORS},\r
-#endif\r
-#ifdef _MIPS_CS_BASE\r
-    {"MIPS_CS_BASE",    _MIPS_CS_BASE},\r
-#endif\r
-#ifdef _MIPS_CS_HOSTID\r
-    {"MIPS_CS_HOSTID",  _MIPS_CS_HOSTID},\r
-#endif\r
-#ifdef _MIPS_CS_HW_NAME\r
-    {"MIPS_CS_HW_NAME", _MIPS_CS_HW_NAME},\r
-#endif\r
-#ifdef _MIPS_CS_NUM_PROCESSORS\r
-    {"MIPS_CS_NUM_PROCESSORS",  _MIPS_CS_NUM_PROCESSORS},\r
-#endif\r
-#ifdef _MIPS_CS_OSREL_MAJ\r
-    {"MIPS_CS_OSREL_MAJ",       _MIPS_CS_OSREL_MAJ},\r
-#endif\r
-#ifdef _MIPS_CS_OSREL_MIN\r
-    {"MIPS_CS_OSREL_MIN",       _MIPS_CS_OSREL_MIN},\r
-#endif\r
-#ifdef _MIPS_CS_OSREL_PATCH\r
-    {"MIPS_CS_OSREL_PATCH",     _MIPS_CS_OSREL_PATCH},\r
-#endif\r
-#ifdef _MIPS_CS_OS_NAME\r
-    {"MIPS_CS_OS_NAME", _MIPS_CS_OS_NAME},\r
-#endif\r
-#ifdef _MIPS_CS_OS_PROVIDER\r
-    {"MIPS_CS_OS_PROVIDER",     _MIPS_CS_OS_PROVIDER},\r
-#endif\r
-#ifdef _MIPS_CS_PROCESSORS\r
-    {"MIPS_CS_PROCESSORS",      _MIPS_CS_PROCESSORS},\r
-#endif\r
-#ifdef _MIPS_CS_SERIAL\r
-    {"MIPS_CS_SERIAL",  _MIPS_CS_SERIAL},\r
-#endif\r
-#ifdef _MIPS_CS_VENDOR\r
-    {"MIPS_CS_VENDOR",  _MIPS_CS_VENDOR},\r
-#endif\r
-};\r
-\r
-static int\r
-conv_confstr_confname(PyObject *arg, int *valuep)\r
-{\r
-    return conv_confname(arg, valuep, posix_constants_confstr,\r
-                         sizeof(posix_constants_confstr)\r
-                           / sizeof(struct constdef));\r
-}\r
-\r
-PyDoc_STRVAR(posix_confstr__doc__,\r
-"confstr(name) -> string\n\n\\r
-Return a string-valued system configuration variable.");\r
-\r
-static PyObject *\r
-posix_confstr(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *result = NULL;\r
-    int name;\r
-    char buffer[256];\r
-\r
-    if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) {\r
-    int len;\r
-\r
-    errno = 0;\r
-    len = confstr(name, buffer, sizeof(buffer));\r
-    if (len == 0) {\r
-        if (errno) {\r
-        posix_error();\r
-        }\r
-        else {\r
-        result = Py_None;\r
-        Py_INCREF(Py_None);\r
-        }\r
-    }\r
-    else {\r
-        if ((unsigned int)len >= sizeof(buffer)) {\r
-        result = PyString_FromStringAndSize(NULL, len-1);\r
-        if (result != NULL)\r
-            confstr(name, PyString_AS_STRING(result), len);\r
-        }\r
-        else\r
-        result = PyString_FromStringAndSize(buffer, len-1);\r
-    }\r
-    }\r
-    return result;\r
-}\r
-#endif\r
-\r
-\r
-#ifdef HAVE_SYSCONF\r
-static struct constdef posix_constants_sysconf[] = {\r
-#ifdef _SC_2_CHAR_TERM\r
-    {"SC_2_CHAR_TERM",  _SC_2_CHAR_TERM},\r
-#endif\r
-#ifdef _SC_2_C_BIND\r
-    {"SC_2_C_BIND",     _SC_2_C_BIND},\r
-#endif\r
-#ifdef _SC_2_C_DEV\r
-    {"SC_2_C_DEV",      _SC_2_C_DEV},\r
-#endif\r
-#ifdef _SC_2_C_VERSION\r
-    {"SC_2_C_VERSION",  _SC_2_C_VERSION},\r
-#endif\r
-#ifdef _SC_2_FORT_DEV\r
-    {"SC_2_FORT_DEV",   _SC_2_FORT_DEV},\r
-#endif\r
-#ifdef _SC_2_FORT_RUN\r
-    {"SC_2_FORT_RUN",   _SC_2_FORT_RUN},\r
-#endif\r
-#ifdef _SC_2_LOCALEDEF\r
-    {"SC_2_LOCALEDEF",  _SC_2_LOCALEDEF},\r
-#endif\r
-#ifdef _SC_2_SW_DEV\r
-    {"SC_2_SW_DEV",     _SC_2_SW_DEV},\r
-#endif\r
-#ifdef _SC_2_UPE\r
-    {"SC_2_UPE",        _SC_2_UPE},\r
-#endif\r
-#ifdef _SC_2_VERSION\r
-    {"SC_2_VERSION",    _SC_2_VERSION},\r
-#endif\r
-#ifdef _SC_ABI_ASYNCHRONOUS_IO\r
-    {"SC_ABI_ASYNCHRONOUS_IO",  _SC_ABI_ASYNCHRONOUS_IO},\r
-#endif\r
-#ifdef _SC_ACL\r
-    {"SC_ACL",  _SC_ACL},\r
-#endif\r
-#ifdef _SC_AIO_LISTIO_MAX\r
-    {"SC_AIO_LISTIO_MAX",       _SC_AIO_LISTIO_MAX},\r
-#endif\r
-#ifdef _SC_AIO_MAX\r
-    {"SC_AIO_MAX",      _SC_AIO_MAX},\r
-#endif\r
-#ifdef _SC_AIO_PRIO_DELTA_MAX\r
-    {"SC_AIO_PRIO_DELTA_MAX",   _SC_AIO_PRIO_DELTA_MAX},\r
-#endif\r
-#ifdef _SC_ARG_MAX\r
-    {"SC_ARG_MAX",      _SC_ARG_MAX},\r
-#endif\r
-#ifdef _SC_ASYNCHRONOUS_IO\r
-    {"SC_ASYNCHRONOUS_IO",      _SC_ASYNCHRONOUS_IO},\r
-#endif\r
-#ifdef _SC_ATEXIT_MAX\r
-    {"SC_ATEXIT_MAX",   _SC_ATEXIT_MAX},\r
-#endif\r
-#ifdef _SC_AUDIT\r
-    {"SC_AUDIT",        _SC_AUDIT},\r
-#endif\r
-#ifdef _SC_AVPHYS_PAGES\r
-    {"SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES},\r
-#endif\r
-#ifdef _SC_BC_BASE_MAX\r
-    {"SC_BC_BASE_MAX",  _SC_BC_BASE_MAX},\r
-#endif\r
-#ifdef _SC_BC_DIM_MAX\r
-    {"SC_BC_DIM_MAX",   _SC_BC_DIM_MAX},\r
-#endif\r
-#ifdef _SC_BC_SCALE_MAX\r
-    {"SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX},\r
-#endif\r
-#ifdef _SC_BC_STRING_MAX\r
-    {"SC_BC_STRING_MAX",        _SC_BC_STRING_MAX},\r
-#endif\r
-#ifdef _SC_CAP\r
-    {"SC_CAP",  _SC_CAP},\r
-#endif\r
-#ifdef _SC_CHARCLASS_NAME_MAX\r
-    {"SC_CHARCLASS_NAME_MAX",   _SC_CHARCLASS_NAME_MAX},\r
-#endif\r
-#ifdef _SC_CHAR_BIT\r
-    {"SC_CHAR_BIT",     _SC_CHAR_BIT},\r
-#endif\r
-#ifdef _SC_CHAR_MAX\r
-    {"SC_CHAR_MAX",     _SC_CHAR_MAX},\r
-#endif\r
-#ifdef _SC_CHAR_MIN\r
-    {"SC_CHAR_MIN",     _SC_CHAR_MIN},\r
-#endif\r
-#ifdef _SC_CHILD_MAX\r
-    {"SC_CHILD_MAX",    _SC_CHILD_MAX},\r
-#endif\r
-#ifdef _SC_CLK_TCK\r
-    {"SC_CLK_TCK",      _SC_CLK_TCK},\r
-#endif\r
-#ifdef _SC_COHER_BLKSZ\r
-    {"SC_COHER_BLKSZ",  _SC_COHER_BLKSZ},\r
-#endif\r
-#ifdef _SC_COLL_WEIGHTS_MAX\r
-    {"SC_COLL_WEIGHTS_MAX",     _SC_COLL_WEIGHTS_MAX},\r
-#endif\r
-#ifdef _SC_DCACHE_ASSOC\r
-    {"SC_DCACHE_ASSOC", _SC_DCACHE_ASSOC},\r
-#endif\r
-#ifdef _SC_DCACHE_BLKSZ\r
-    {"SC_DCACHE_BLKSZ", _SC_DCACHE_BLKSZ},\r
-#endif\r
-#ifdef _SC_DCACHE_LINESZ\r
-    {"SC_DCACHE_LINESZ",        _SC_DCACHE_LINESZ},\r
-#endif\r
-#ifdef _SC_DCACHE_SZ\r
-    {"SC_DCACHE_SZ",    _SC_DCACHE_SZ},\r
-#endif\r
-#ifdef _SC_DCACHE_TBLKSZ\r
-    {"SC_DCACHE_TBLKSZ",        _SC_DCACHE_TBLKSZ},\r
-#endif\r
-#ifdef _SC_DELAYTIMER_MAX\r
-    {"SC_DELAYTIMER_MAX",       _SC_DELAYTIMER_MAX},\r
-#endif\r
-#ifdef _SC_EQUIV_CLASS_MAX\r
-    {"SC_EQUIV_CLASS_MAX",      _SC_EQUIV_CLASS_MAX},\r
-#endif\r
-#ifdef _SC_EXPR_NEST_MAX\r
-    {"SC_EXPR_NEST_MAX",        _SC_EXPR_NEST_MAX},\r
-#endif\r
-#ifdef _SC_FSYNC\r
-    {"SC_FSYNC",        _SC_FSYNC},\r
-#endif\r
-#ifdef _SC_GETGR_R_SIZE_MAX\r
-    {"SC_GETGR_R_SIZE_MAX",     _SC_GETGR_R_SIZE_MAX},\r
-#endif\r
-#ifdef _SC_GETPW_R_SIZE_MAX\r
-    {"SC_GETPW_R_SIZE_MAX",     _SC_GETPW_R_SIZE_MAX},\r
-#endif\r
-#ifdef _SC_ICACHE_ASSOC\r
-    {"SC_ICACHE_ASSOC", _SC_ICACHE_ASSOC},\r
-#endif\r
-#ifdef _SC_ICACHE_BLKSZ\r
-    {"SC_ICACHE_BLKSZ", _SC_ICACHE_BLKSZ},\r
-#endif\r
-#ifdef _SC_ICACHE_LINESZ\r
-    {"SC_ICACHE_LINESZ",        _SC_ICACHE_LINESZ},\r
-#endif\r
-#ifdef _SC_ICACHE_SZ\r
-    {"SC_ICACHE_SZ",    _SC_ICACHE_SZ},\r
-#endif\r
-#ifdef _SC_INF\r
-    {"SC_INF",  _SC_INF},\r
-#endif\r
-#ifdef _SC_INT_MAX\r
-    {"SC_INT_MAX",      _SC_INT_MAX},\r
-#endif\r
-#ifdef _SC_INT_MIN\r
-    {"SC_INT_MIN",      _SC_INT_MIN},\r
-#endif\r
-#ifdef _SC_IOV_MAX\r
-    {"SC_IOV_MAX",      _SC_IOV_MAX},\r
-#endif\r
-#ifdef _SC_IP_SECOPTS\r
-    {"SC_IP_SECOPTS",   _SC_IP_SECOPTS},\r
-#endif\r
-#ifdef _SC_JOB_CONTROL\r
-    {"SC_JOB_CONTROL",  _SC_JOB_CONTROL},\r
-#endif\r
-#ifdef _SC_KERN_POINTERS\r
-    {"SC_KERN_POINTERS",        _SC_KERN_POINTERS},\r
-#endif\r
-#ifdef _SC_KERN_SIM\r
-    {"SC_KERN_SIM",     _SC_KERN_SIM},\r
-#endif\r
-#ifdef _SC_LINE_MAX\r
-    {"SC_LINE_MAX",     _SC_LINE_MAX},\r
-#endif\r
-#ifdef _SC_LOGIN_NAME_MAX\r
-    {"SC_LOGIN_NAME_MAX",       _SC_LOGIN_NAME_MAX},\r
-#endif\r
-#ifdef _SC_LOGNAME_MAX\r
-    {"SC_LOGNAME_MAX",  _SC_LOGNAME_MAX},\r
-#endif\r
-#ifdef _SC_LONG_BIT\r
-    {"SC_LONG_BIT",     _SC_LONG_BIT},\r
-#endif\r
-#ifdef _SC_MAC\r
-    {"SC_MAC",  _SC_MAC},\r
-#endif\r
-#ifdef _SC_MAPPED_FILES\r
-    {"SC_MAPPED_FILES", _SC_MAPPED_FILES},\r
-#endif\r
-#ifdef _SC_MAXPID\r
-    {"SC_MAXPID",       _SC_MAXPID},\r
-#endif\r
-#ifdef _SC_MB_LEN_MAX\r
-    {"SC_MB_LEN_MAX",   _SC_MB_LEN_MAX},\r
-#endif\r
-#ifdef _SC_MEMLOCK\r
-    {"SC_MEMLOCK",      _SC_MEMLOCK},\r
-#endif\r
-#ifdef _SC_MEMLOCK_RANGE\r
-    {"SC_MEMLOCK_RANGE",        _SC_MEMLOCK_RANGE},\r
-#endif\r
-#ifdef _SC_MEMORY_PROTECTION\r
-    {"SC_MEMORY_PROTECTION",    _SC_MEMORY_PROTECTION},\r
-#endif\r
-#ifdef _SC_MESSAGE_PASSING\r
-    {"SC_MESSAGE_PASSING",      _SC_MESSAGE_PASSING},\r
-#endif\r
-#ifdef _SC_MMAP_FIXED_ALIGNMENT\r
-    {"SC_MMAP_FIXED_ALIGNMENT", _SC_MMAP_FIXED_ALIGNMENT},\r
-#endif\r
-#ifdef _SC_MQ_OPEN_MAX\r
-    {"SC_MQ_OPEN_MAX",  _SC_MQ_OPEN_MAX},\r
-#endif\r
-#ifdef _SC_MQ_PRIO_MAX\r
-    {"SC_MQ_PRIO_MAX",  _SC_MQ_PRIO_MAX},\r
-#endif\r
-#ifdef _SC_NACLS_MAX\r
-    {"SC_NACLS_MAX",    _SC_NACLS_MAX},\r
-#endif\r
-#ifdef _SC_NGROUPS_MAX\r
-    {"SC_NGROUPS_MAX",  _SC_NGROUPS_MAX},\r
-#endif\r
-#ifdef _SC_NL_ARGMAX\r
-    {"SC_NL_ARGMAX",    _SC_NL_ARGMAX},\r
-#endif\r
-#ifdef _SC_NL_LANGMAX\r
-    {"SC_NL_LANGMAX",   _SC_NL_LANGMAX},\r
-#endif\r
-#ifdef _SC_NL_MSGMAX\r
-    {"SC_NL_MSGMAX",    _SC_NL_MSGMAX},\r
-#endif\r
-#ifdef _SC_NL_NMAX\r
-    {"SC_NL_NMAX",      _SC_NL_NMAX},\r
-#endif\r
-#ifdef _SC_NL_SETMAX\r
-    {"SC_NL_SETMAX",    _SC_NL_SETMAX},\r
-#endif\r
-#ifdef _SC_NL_TEXTMAX\r
-    {"SC_NL_TEXTMAX",   _SC_NL_TEXTMAX},\r
-#endif\r
-#ifdef _SC_NPROCESSORS_CONF\r
-    {"SC_NPROCESSORS_CONF",     _SC_NPROCESSORS_CONF},\r
-#endif\r
-#ifdef _SC_NPROCESSORS_ONLN\r
-    {"SC_NPROCESSORS_ONLN",     _SC_NPROCESSORS_ONLN},\r
-#endif\r
-#ifdef _SC_NPROC_CONF\r
-    {"SC_NPROC_CONF",   _SC_NPROC_CONF},\r
-#endif\r
-#ifdef _SC_NPROC_ONLN\r
-    {"SC_NPROC_ONLN",   _SC_NPROC_ONLN},\r
-#endif\r
-#ifdef _SC_NZERO\r
-    {"SC_NZERO",        _SC_NZERO},\r
-#endif\r
-#ifdef _SC_OPEN_MAX\r
-    {"SC_OPEN_MAX",     _SC_OPEN_MAX},\r
-#endif\r
-#ifdef _SC_PAGESIZE\r
-    {"SC_PAGESIZE",     _SC_PAGESIZE},\r
-#endif\r
-#ifdef _SC_PAGE_SIZE\r
-    {"SC_PAGE_SIZE",    _SC_PAGE_SIZE},\r
-#endif\r
-#ifdef _SC_PASS_MAX\r
-    {"SC_PASS_MAX",     _SC_PASS_MAX},\r
-#endif\r
-#ifdef _SC_PHYS_PAGES\r
-    {"SC_PHYS_PAGES",   _SC_PHYS_PAGES},\r
-#endif\r
-#ifdef _SC_PII\r
-    {"SC_PII",  _SC_PII},\r
-#endif\r
-#ifdef _SC_PII_INTERNET\r
-    {"SC_PII_INTERNET", _SC_PII_INTERNET},\r
-#endif\r
-#ifdef _SC_PII_INTERNET_DGRAM\r
-    {"SC_PII_INTERNET_DGRAM",   _SC_PII_INTERNET_DGRAM},\r
-#endif\r
-#ifdef _SC_PII_INTERNET_STREAM\r
-    {"SC_PII_INTERNET_STREAM",  _SC_PII_INTERNET_STREAM},\r
-#endif\r
-#ifdef _SC_PII_OSI\r
-    {"SC_PII_OSI",      _SC_PII_OSI},\r
-#endif\r
-#ifdef _SC_PII_OSI_CLTS\r
-    {"SC_PII_OSI_CLTS", _SC_PII_OSI_CLTS},\r
-#endif\r
-#ifdef _SC_PII_OSI_COTS\r
-    {"SC_PII_OSI_COTS", _SC_PII_OSI_COTS},\r
-#endif\r
-#ifdef _SC_PII_OSI_M\r
-    {"SC_PII_OSI_M",    _SC_PII_OSI_M},\r
-#endif\r
-#ifdef _SC_PII_SOCKET\r
-    {"SC_PII_SOCKET",   _SC_PII_SOCKET},\r
-#endif\r
-#ifdef _SC_PII_XTI\r
-    {"SC_PII_XTI",      _SC_PII_XTI},\r
-#endif\r
-#ifdef _SC_POLL\r
-    {"SC_POLL", _SC_POLL},\r
-#endif\r
-#ifdef _SC_PRIORITIZED_IO\r
-    {"SC_PRIORITIZED_IO",       _SC_PRIORITIZED_IO},\r
-#endif\r
-#ifdef _SC_PRIORITY_SCHEDULING\r
-    {"SC_PRIORITY_SCHEDULING",  _SC_PRIORITY_SCHEDULING},\r
-#endif\r
-#ifdef _SC_REALTIME_SIGNALS\r
-    {"SC_REALTIME_SIGNALS",     _SC_REALTIME_SIGNALS},\r
-#endif\r
-#ifdef _SC_RE_DUP_MAX\r
-    {"SC_RE_DUP_MAX",   _SC_RE_DUP_MAX},\r
-#endif\r
-#ifdef _SC_RTSIG_MAX\r
-    {"SC_RTSIG_MAX",    _SC_RTSIG_MAX},\r
-#endif\r
-#ifdef _SC_SAVED_IDS\r
-    {"SC_SAVED_IDS",    _SC_SAVED_IDS},\r
-#endif\r
-#ifdef _SC_SCHAR_MAX\r
-    {"SC_SCHAR_MAX",    _SC_SCHAR_MAX},\r
-#endif\r
-#ifdef _SC_SCHAR_MIN\r
-    {"SC_SCHAR_MIN",    _SC_SCHAR_MIN},\r
-#endif\r
-#ifdef _SC_SELECT\r
-    {"SC_SELECT",       _SC_SELECT},\r
-#endif\r
-#ifdef _SC_SEMAPHORES\r
-    {"SC_SEMAPHORES",   _SC_SEMAPHORES},\r
-#endif\r
-#ifdef _SC_SEM_NSEMS_MAX\r
-    {"SC_SEM_NSEMS_MAX",        _SC_SEM_NSEMS_MAX},\r
-#endif\r
-#ifdef _SC_SEM_VALUE_MAX\r
-    {"SC_SEM_VALUE_MAX",        _SC_SEM_VALUE_MAX},\r
-#endif\r
-#ifdef _SC_SHARED_MEMORY_OBJECTS\r
-    {"SC_SHARED_MEMORY_OBJECTS",        _SC_SHARED_MEMORY_OBJECTS},\r
-#endif\r
-#ifdef _SC_SHRT_MAX\r
-    {"SC_SHRT_MAX",     _SC_SHRT_MAX},\r
-#endif\r
-#ifdef _SC_SHRT_MIN\r
-    {"SC_SHRT_MIN",     _SC_SHRT_MIN},\r
-#endif\r
-#ifdef _SC_SIGQUEUE_MAX\r
-    {"SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX},\r
-#endif\r
-#ifdef _SC_SIGRT_MAX\r
-    {"SC_SIGRT_MAX",    _SC_SIGRT_MAX},\r
-#endif\r
-#ifdef _SC_SIGRT_MIN\r
-    {"SC_SIGRT_MIN",    _SC_SIGRT_MIN},\r
-#endif\r
-#ifdef _SC_SOFTPOWER\r
-    {"SC_SOFTPOWER",    _SC_SOFTPOWER},\r
-#endif\r
-#ifdef _SC_SPLIT_CACHE\r
-    {"SC_SPLIT_CACHE",  _SC_SPLIT_CACHE},\r
-#endif\r
-#ifdef _SC_SSIZE_MAX\r
-    {"SC_SSIZE_MAX",    _SC_SSIZE_MAX},\r
-#endif\r
-#ifdef _SC_STACK_PROT\r
-    {"SC_STACK_PROT",   _SC_STACK_PROT},\r
-#endif\r
-#ifdef _SC_STREAM_MAX\r
-    {"SC_STREAM_MAX",   _SC_STREAM_MAX},\r
-#endif\r
-#ifdef _SC_SYNCHRONIZED_IO\r
-    {"SC_SYNCHRONIZED_IO",      _SC_SYNCHRONIZED_IO},\r
-#endif\r
-#ifdef _SC_THREADS\r
-    {"SC_THREADS",      _SC_THREADS},\r
-#endif\r
-#ifdef _SC_THREAD_ATTR_STACKADDR\r
-    {"SC_THREAD_ATTR_STACKADDR",        _SC_THREAD_ATTR_STACKADDR},\r
-#endif\r
-#ifdef _SC_THREAD_ATTR_STACKSIZE\r
-    {"SC_THREAD_ATTR_STACKSIZE",        _SC_THREAD_ATTR_STACKSIZE},\r
-#endif\r
-#ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS\r
-    {"SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS},\r
-#endif\r
-#ifdef _SC_THREAD_KEYS_MAX\r
-    {"SC_THREAD_KEYS_MAX",      _SC_THREAD_KEYS_MAX},\r
-#endif\r
-#ifdef _SC_THREAD_PRIORITY_SCHEDULING\r
-    {"SC_THREAD_PRIORITY_SCHEDULING",   _SC_THREAD_PRIORITY_SCHEDULING},\r
-#endif\r
-#ifdef _SC_THREAD_PRIO_INHERIT\r
-    {"SC_THREAD_PRIO_INHERIT",  _SC_THREAD_PRIO_INHERIT},\r
-#endif\r
-#ifdef _SC_THREAD_PRIO_PROTECT\r
-    {"SC_THREAD_PRIO_PROTECT",  _SC_THREAD_PRIO_PROTECT},\r
-#endif\r
-#ifdef _SC_THREAD_PROCESS_SHARED\r
-    {"SC_THREAD_PROCESS_SHARED",        _SC_THREAD_PROCESS_SHARED},\r
-#endif\r
-#ifdef _SC_THREAD_SAFE_FUNCTIONS\r
-    {"SC_THREAD_SAFE_FUNCTIONS",        _SC_THREAD_SAFE_FUNCTIONS},\r
-#endif\r
-#ifdef _SC_THREAD_STACK_MIN\r
-    {"SC_THREAD_STACK_MIN",     _SC_THREAD_STACK_MIN},\r
-#endif\r
-#ifdef _SC_THREAD_THREADS_MAX\r
-    {"SC_THREAD_THREADS_MAX",   _SC_THREAD_THREADS_MAX},\r
-#endif\r
-#ifdef _SC_TIMERS\r
-    {"SC_TIMERS",       _SC_TIMERS},\r
-#endif\r
-#ifdef _SC_TIMER_MAX\r
-    {"SC_TIMER_MAX",    _SC_TIMER_MAX},\r
-#endif\r
-#ifdef _SC_TTY_NAME_MAX\r
-    {"SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX},\r
-#endif\r
-#ifdef _SC_TZNAME_MAX\r
-    {"SC_TZNAME_MAX",   _SC_TZNAME_MAX},\r
-#endif\r
-#ifdef _SC_T_IOV_MAX\r
-    {"SC_T_IOV_MAX",    _SC_T_IOV_MAX},\r
-#endif\r
-#ifdef _SC_UCHAR_MAX\r
-    {"SC_UCHAR_MAX",    _SC_UCHAR_MAX},\r
-#endif\r
-#ifdef _SC_UINT_MAX\r
-    {"SC_UINT_MAX",     _SC_UINT_MAX},\r
-#endif\r
-#ifdef _SC_UIO_MAXIOV\r
-    {"SC_UIO_MAXIOV",   _SC_UIO_MAXIOV},\r
-#endif\r
-#ifdef _SC_ULONG_MAX\r
-    {"SC_ULONG_MAX",    _SC_ULONG_MAX},\r
-#endif\r
-#ifdef _SC_USHRT_MAX\r
-    {"SC_USHRT_MAX",    _SC_USHRT_MAX},\r
-#endif\r
-#ifdef _SC_VERSION\r
-    {"SC_VERSION",      _SC_VERSION},\r
-#endif\r
-#ifdef _SC_WORD_BIT\r
-    {"SC_WORD_BIT",     _SC_WORD_BIT},\r
-#endif\r
-#ifdef _SC_XBS5_ILP32_OFF32\r
-    {"SC_XBS5_ILP32_OFF32",     _SC_XBS5_ILP32_OFF32},\r
-#endif\r
-#ifdef _SC_XBS5_ILP32_OFFBIG\r
-    {"SC_XBS5_ILP32_OFFBIG",    _SC_XBS5_ILP32_OFFBIG},\r
-#endif\r
-#ifdef _SC_XBS5_LP64_OFF64\r
-    {"SC_XBS5_LP64_OFF64",      _SC_XBS5_LP64_OFF64},\r
-#endif\r
-#ifdef _SC_XBS5_LPBIG_OFFBIG\r
-    {"SC_XBS5_LPBIG_OFFBIG",    _SC_XBS5_LPBIG_OFFBIG},\r
-#endif\r
-#ifdef _SC_XOPEN_CRYPT\r
-    {"SC_XOPEN_CRYPT",  _SC_XOPEN_CRYPT},\r
-#endif\r
-#ifdef _SC_XOPEN_ENH_I18N\r
-    {"SC_XOPEN_ENH_I18N",       _SC_XOPEN_ENH_I18N},\r
-#endif\r
-#ifdef _SC_XOPEN_LEGACY\r
-    {"SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY},\r
-#endif\r
-#ifdef _SC_XOPEN_REALTIME\r
-    {"SC_XOPEN_REALTIME",       _SC_XOPEN_REALTIME},\r
-#endif\r
-#ifdef _SC_XOPEN_REALTIME_THREADS\r
-    {"SC_XOPEN_REALTIME_THREADS",       _SC_XOPEN_REALTIME_THREADS},\r
-#endif\r
-#ifdef _SC_XOPEN_SHM\r
-    {"SC_XOPEN_SHM",    _SC_XOPEN_SHM},\r
-#endif\r
-#ifdef _SC_XOPEN_UNIX\r
-    {"SC_XOPEN_UNIX",   _SC_XOPEN_UNIX},\r
-#endif\r
-#ifdef _SC_XOPEN_VERSION\r
-    {"SC_XOPEN_VERSION",        _SC_XOPEN_VERSION},\r
-#endif\r
-#ifdef _SC_XOPEN_XCU_VERSION\r
-    {"SC_XOPEN_XCU_VERSION",    _SC_XOPEN_XCU_VERSION},\r
-#endif\r
-#ifdef _SC_XOPEN_XPG2\r
-    {"SC_XOPEN_XPG2",   _SC_XOPEN_XPG2},\r
-#endif\r
-#ifdef _SC_XOPEN_XPG3\r
-    {"SC_XOPEN_XPG3",   _SC_XOPEN_XPG3},\r
-#endif\r
-#ifdef _SC_XOPEN_XPG4\r
-    {"SC_XOPEN_XPG4",   _SC_XOPEN_XPG4},\r
-#endif\r
-};\r
+    return Py_BuildValue("i", WEXITSTATUS(status));\r
+}\r
+#endif /* WEXITSTATUS */\r
 \r
 \r
-static int\r
-conv_sysconf_confname(PyObject *arg, int *valuep)\r
+#ifdef WTERMSIG\r
+PyDoc_STRVAR(posix_WTERMSIG__doc__,\r
+"WTERMSIG(status) -> integer\n\n\\r
+Return the signal that terminated the process that provided the 'status'\n\\r
+value.");\r
+\r
+static PyObject *\r
+posix_WTERMSIG(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    return conv_confname(arg, valuep, posix_constants_sysconf,\r
-                         sizeof(posix_constants_sysconf)\r
-                           / sizeof(struct constdef));\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
+\r
+    if (!PyArg_ParseTuple(args, "i:WTERMSIG", &WAIT_STATUS_INT(status)))\r
+        return NULL;\r
+\r
+    return Py_BuildValue("i", WTERMSIG(status));\r
 }\r
 }\r
+#endif /* WTERMSIG */\r
 \r
 \r
-PyDoc_STRVAR(posix_sysconf__doc__,\r
-"sysconf(name) -> integer\n\n\\r
-Return an integer-valued system configuration variable.");\r
+#ifdef WSTOPSIG\r
+PyDoc_STRVAR(posix_WSTOPSIG__doc__,\r
+"WSTOPSIG(status) -> integer\n\n\\r
+Return the signal that stopped the process that provided\n\\r
+the 'status' value.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_sysconf(PyObject *self, PyObject *args)\r
+posix_WSTOPSIG(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *result = NULL;\r
-    int name;\r
+    WAIT_TYPE status;\r
+    WAIT_STATUS_INT(status) = 0;\r
 \r
 \r
-    if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) {\r
-        int value;\r
+    if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &WAIT_STATUS_INT(status)))\r
+        return NULL;\r
 \r
 \r
-        errno = 0;\r
-        value = sysconf(name);\r
-        if (value == -1 && errno != 0)\r
-            posix_error();\r
-        else\r
-            result = PyInt_FromLong(value);\r
-    }\r
-    return result;\r
+    return Py_BuildValue("i", WSTOPSIG(status));\r
 }\r
 }\r
-#endif\r
+#endif /* WSTOPSIG */\r
 \r
 \r
+#endif /* HAVE_SYS_WAIT_H */\r
 \r
 \r
-#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF) || defined(HAVE_CONFSTR) || defined(HAVE_SYSCONF)\r
-/* This code is used to ensure that the tables of configuration value names\r
- * are in sorted order as required by conv_confname(), and also to build the\r
- * the exported dictionaries that are used to publish information about the\r
- * names available on the host platform.\r
- *\r
- * Sorting the table at runtime ensures that the table is properly ordered\r
- * when used, even for platforms we're not able to test on.  It also makes\r
- * it easier to add additional entries to the tables.\r
- */\r
 \r
 \r
-static int\r
-cmp_constdefs(const void *v1,  const void *v2)\r
-{\r
-    const struct constdef *c1 =\r
-    (const struct constdef *) v1;\r
-    const struct constdef *c2 =\r
-    (const struct constdef *) v2;\r
+#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)\r
+#include <sys/statvfs.h>\r
+\r
+static PyObject*\r
+_pystatvfs_fromstructstatvfs(struct statvfs st) {\r
+    PyObject *v = PyStructSequence_New(&StatVFSResultType);\r
+    if (v == NULL)\r
+        return NULL;\r
+\r
+#if !defined(HAVE_LARGEFILE_SUPPORT)\r
+    PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));\r
+    PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));\r
+    PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) st.f_blocks));\r
+    PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) st.f_bfree));\r
+    PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) st.f_bavail));\r
+    PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) st.f_files));\r
+    PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long) st.f_ffree));\r
+    PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) st.f_favail));\r
+    PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));\r
+    PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));\r
+#else\r
+    PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));\r
+    PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));\r
+    PyStructSequence_SET_ITEM(v, 2,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_blocks));\r
+    PyStructSequence_SET_ITEM(v, 3,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_bfree));\r
+    PyStructSequence_SET_ITEM(v, 4,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_bavail));\r
+    PyStructSequence_SET_ITEM(v, 5,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_files));\r
+    PyStructSequence_SET_ITEM(v, 6,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_ffree));\r
+    PyStructSequence_SET_ITEM(v, 7,\r
+                              PyLong_FromLongLong((PY_LONG_LONG) st.f_favail));\r
+    PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));\r
+    PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));\r
+#endif\r
 \r
 \r
-    return strcmp(c1->name, c2->name);\r
+    return v;\r
 }\r
 \r
 }\r
 \r
-static int\r
-setup_confname_table(struct constdef *table, size_t tablesize,\r
-                     char *tablename, PyObject *module)\r
+PyDoc_STRVAR(posix_fstatvfs__doc__,\r
+"fstatvfs(fd) -> statvfs result\n\n\\r
+Perform an fstatvfs system call on the given fd.");\r
+\r
+static PyObject *\r
+posix_fstatvfs(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    PyObject *d = NULL;\r
-    size_t i;\r
+    int fd, res;\r
+    struct statvfs st;\r
 \r
 \r
-    qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);\r
-    d = PyDict_New();\r
-    if (d == NULL)\r
-        return -1;\r
+    if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd))\r
+        return NULL;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = fstatvfs(fd, &st);\r
+    Py_END_ALLOW_THREADS\r
+    if (res != 0)\r
+        return posix_error();\r
 \r
 \r
-    for (i=0; i < tablesize; ++i) {\r
-        PyObject *o = PyInt_FromLong(table[i].value);\r
-        if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {\r
-            Py_XDECREF(o);\r
-            Py_DECREF(d);\r
-            return -1;\r
-        }\r
-        Py_DECREF(o);\r
-    }\r
-    return PyModule_AddObject(module, tablename, d);\r
+    return _pystatvfs_fromstructstatvfs(st);\r
 }\r
 }\r
-#endif  /* HAVE_FPATHCONF || HAVE_PATHCONF || HAVE_CONFSTR || HAVE_SYSCONF */\r
+#endif /* HAVE_FSTATVFS && HAVE_SYS_STATVFS_H */\r
 \r
 \r
-/* Return -1 on failure, 0 on success. */\r
-static int\r
-setup_confname_tables(PyObject *module)\r
+\r
+#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)\r
+#include <sys/statvfs.h>\r
+\r
+PyDoc_STRVAR(posix_statvfs__doc__,\r
+"statvfs(path) -> statvfs result\n\n\\r
+Perform a statvfs system call on the given path.");\r
+\r
+static PyObject *\r
+posix_statvfs(PyObject *self, PyObject *args)\r
 {\r
 {\r
-#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)\r
-    if (setup_confname_table(posix_constants_pathconf,\r
-                             sizeof(posix_constants_pathconf)\r
-                               / sizeof(struct constdef),\r
-                             "pathconf_names", module))\r
-        return -1;\r
-#endif\r
-#ifdef HAVE_CONFSTR\r
-    if (setup_confname_table(posix_constants_confstr,\r
-                             sizeof(posix_constants_confstr)\r
-                               / sizeof(struct constdef),\r
-                             "confstr_names", module))\r
-        return -1;\r
-#endif\r
-#ifdef HAVE_SYSCONF\r
-    if (setup_confname_table(posix_constants_sysconf,\r
-                             sizeof(posix_constants_sysconf)\r
-                               / sizeof(struct constdef),\r
-                             "sysconf_names", module))\r
-        return -1;\r
-#endif\r
-    return 0;\r
+    char *path;\r
+    int res;\r
+    struct statvfs st;\r
+    if (!PyArg_ParseTuple(args, "s:statvfs", &path))\r
+        return NULL;\r
+    Py_BEGIN_ALLOW_THREADS\r
+    res = statvfs(path, &st);\r
+    Py_END_ALLOW_THREADS\r
+    if (res != 0)\r
+        return posix_error_with_filename(path);\r
+\r
+    return _pystatvfs_fromstructstatvfs(st);\r
 }\r
 }\r
+#endif /* HAVE_STATVFS */\r
 \r
 \r
 \r
 \r
-PyDoc_STRVAR(posix_abort__doc__,\r
-"abort() -> does not return!\n\n\\r
-Abort the interpreter immediately.  This 'dumps core' or otherwise fails\n\\r
-in the hardest way possible on the hosting operating system.");\r
+#ifdef HAVE_TEMPNAM\r
+PyDoc_STRVAR(posix_tempnam__doc__,\r
+"tempnam([dir[, prefix]]) -> string\n\n\\r
+Return a unique name for a temporary file.\n\\r
+The directory and a prefix may be specified as strings; they may be omitted\n\\r
+or None if not needed.");\r
 \r
 static PyObject *\r
 \r
 static PyObject *\r
-posix_abort(PyObject *self, PyObject *noargs)\r
+posix_tempnam(PyObject *self, PyObject *args)\r
 {\r
 {\r
-    abort();\r
-    /*NOTREACHED*/\r
-    Py_FatalError("abort() called from Python code didn't abort!");\r
+    PyObject *result = NULL;\r
+    char *dir = NULL;\r
+    char *pfx = NULL;\r
+    char *name;\r
+\r
+    if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx))\r
     return NULL;\r
     return NULL;\r
-}\r
 \r
 \r
-#ifdef HAVE_SETRESUID\r
-PyDoc_STRVAR(posix_setresuid__doc__,\r
-"setresuid(ruid, euid, suid)\n\n\\r
-Set the current process's real, effective, and saved user ids.");\r
+    if (PyErr_Warn(PyExc_RuntimeWarning,\r
+                   "tempnam is a potential security risk to your program") < 0)\r
+        return NULL;\r
 \r
 \r
-static PyObject*\r
-posix_setresuid (PyObject *self, PyObject *args)\r
-{\r
-    /* We assume uid_t is no larger than a long. */\r
-    long ruid, euid, suid;\r
-    if (!PyArg_ParseTuple(args, "lll", &ruid, &euid, &suid))\r
+    if (PyErr_WarnPy3k("tempnam has been removed in 3.x; "\r
+                       "use the tempfile module", 1) < 0)\r
         return NULL;\r
         return NULL;\r
-    if (setresuid(ruid, euid, suid) < 0)\r
-        return posix_error();\r
-    Py_RETURN_NONE;\r
+\r
+    name = tempnam(dir, pfx);\r
+    if (name == NULL)\r
+        return PyErr_NoMemory();\r
+    result = PyString_FromString(name);\r
+    free(name);\r
+    return result;\r
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifdef HAVE_SETRESGID\r
-PyDoc_STRVAR(posix_setresgid__doc__,\r
-"setresgid(rgid, egid, sgid)\n\n\\r
-Set the current process's real, effective, and saved group ids.");\r
 \r
 \r
-static PyObject*\r
-posix_setresgid (PyObject *self, PyObject *args)\r
+#ifdef HAVE_TMPFILE\r
+PyDoc_STRVAR(posix_tmpfile__doc__,\r
+"tmpfile() -> file object\n\n\\r
+Create a temporary file with no directory entries.");\r
+\r
+static PyObject *\r
+posix_tmpfile(PyObject *self, PyObject *noargs)\r
 {\r
 {\r
-    /* We assume uid_t is no larger than a long. */\r
-    long rgid, egid, sgid;\r
-    if (!PyArg_ParseTuple(args, "lll", &rgid, &egid, &sgid))\r
+    FILE *fp;\r
+\r
+    if (PyErr_WarnPy3k("tmpfile has been removed in 3.x; "\r
+                       "use the tempfile module", 1) < 0)\r
         return NULL;\r
         return NULL;\r
-    if (setresgid(rgid, egid, sgid) < 0)\r
+\r
+    fp = tmpfile();\r
+    if (fp == NULL)\r
         return posix_error();\r
         return posix_error();\r
-    Py_RETURN_NONE;\r
+    return PyFile_FromFile(fp, "<tmpfile>", "w+b", fclose);\r
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifdef HAVE_GETRESUID\r
-PyDoc_STRVAR(posix_getresuid__doc__,\r
-"getresuid() -> (ruid, euid, suid)\n\n\\r
-Get tuple of the current process's real, effective, and saved user ids.");\r
 \r
 \r
-static PyObject*\r
-posix_getresuid (PyObject *self, PyObject *noargs)\r
+#ifdef HAVE_TMPNAM\r
+PyDoc_STRVAR(posix_tmpnam__doc__,\r
+"tmpnam() -> string\n\n\\r
+Return a unique name for a temporary file.");\r
+\r
+static PyObject *\r
+posix_tmpnam(PyObject *self, PyObject *noargs)\r
 {\r
 {\r
-    uid_t ruid, euid, suid;\r
-    long l_ruid, l_euid, l_suid;\r
-    if (getresuid(&ruid, &euid, &suid) < 0)\r
-        return posix_error();\r
-    /* Force the values into long's as we don't know the size of uid_t. */\r
-    l_ruid = ruid;\r
-    l_euid = euid;\r
-    l_suid = suid;\r
-    return Py_BuildValue("(lll)", l_ruid, l_euid, l_suid);\r
+    char buffer[L_tmpnam];\r
+    char *name;\r
+\r
+    if (PyErr_Warn(PyExc_RuntimeWarning,\r
+                   "tmpnam is a potential security risk to your program") < 0)\r
+        return NULL;\r
+\r
+    if (PyErr_WarnPy3k("tmpnam has been removed in 3.x; "\r
+                       "use the tempfile module", 1) < 0)\r
+        return NULL;\r
+\r
+#ifdef USE_TMPNAM_R\r
+    name = tmpnam_r(buffer);\r
+#else\r
+    name = tmpnam(buffer);\r
+#endif\r
+    if (name == NULL) {\r
+        PyObject *err = Py_BuildValue("is", 0,\r
+#ifdef USE_TMPNAM_R\r
+                                      "unexpected NULL from tmpnam_r"\r
+#else\r
+                                      "unexpected NULL from tmpnam"\r
+#endif\r
+                                      );\r
+        PyErr_SetObject(PyExc_OSError, err);\r
+        Py_XDECREF(err);\r
+        return NULL;\r
+    }\r
+    return PyString_FromString(buffer);\r
 }\r
 #endif\r
 \r
 }\r
 #endif\r
 \r
-#ifdef HAVE_GETRESGID\r
-PyDoc_STRVAR(posix_getresgid__doc__,\r
-"getresgid() -> (rgid, egid, sgid)\n\n\\r
-Get tuple of the current process's real, effective, and saved group ids.");\r
+PyDoc_STRVAR(posix_abort__doc__,\r
+"abort() -> does not return!\n\n\\r
+Abort the interpreter immediately.  This 'dumps core' or otherwise fails\n\\r
+in the hardest way possible on the hosting operating system.");\r
 \r
 \r
-static PyObject*\r
-posix_getresgid (PyObject *self, PyObject *noargs)\r
+static PyObject *\r
+posix_abort(PyObject *self, PyObject *noargs)\r
 {\r
 {\r
-    uid_t rgid, egid, sgid;\r
-    long l_rgid, l_egid, l_sgid;\r
-    if (getresgid(&rgid, &egid, &sgid) < 0)\r
-        return posix_error();\r
-    /* Force the values into long's as we don't know the size of uid_t. */\r
-    l_rgid = rgid;\r
-    l_egid = egid;\r
-    l_sgid = sgid;\r
-    return Py_BuildValue("(lll)", l_rgid, l_egid, l_sgid);\r
+    abort();\r
+    /*NOTREACHED*/\r
+    Py_FatalError("abort() called from Python code didn't abort!");\r
+    return NULL;\r
 }\r
 }\r
-#endif\r
 \r
 static PyMethodDef posix_methods[] = {\r
     {"access",          posix_access,     METH_VARARGS, posix_access__doc__},\r
 \r
 static PyMethodDef posix_methods[] = {\r
     {"access",          posix_access,     METH_VARARGS, posix_access__doc__},\r
@@ -6897,18 +3793,6 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_FORKPTY\r
     {"forkpty",         posix_forkpty, METH_NOARGS, posix_forkpty__doc__},\r
 #endif /* HAVE_FORKPTY */\r
 #ifdef HAVE_FORKPTY\r
     {"forkpty",         posix_forkpty, METH_NOARGS, posix_forkpty__doc__},\r
 #endif /* HAVE_FORKPTY */\r
-#ifdef HAVE_GETEGID\r
-    {"getegid",         posix_getegid, METH_NOARGS, posix_getegid__doc__},\r
-#endif /* HAVE_GETEGID */\r
-#ifdef HAVE_GETEUID\r
-    {"geteuid",         posix_geteuid, METH_NOARGS, posix_geteuid__doc__},\r
-#endif /* HAVE_GETEUID */\r
-#ifdef HAVE_GETGID\r
-    {"getgid",          posix_getgid, METH_NOARGS, posix_getgid__doc__},\r
-#endif /* HAVE_GETGID */\r
-#ifdef HAVE_GETGROUPS\r
-    {"getgroups",       posix_getgroups, METH_NOARGS, posix_getgroups__doc__},\r
-#endif\r
     {"getpid",          posix_getpid,     METH_NOARGS,  posix_getpid__doc__},\r
 #ifdef HAVE_GETPGRP\r
     {"getpgrp",         posix_getpgrp, METH_NOARGS, posix_getpgrp__doc__},\r
     {"getpid",          posix_getpid,     METH_NOARGS,  posix_getpid__doc__},\r
 #ifdef HAVE_GETPGRP\r
     {"getpgrp",         posix_getpgrp, METH_NOARGS, posix_getpgrp__doc__},\r
@@ -6916,9 +3800,6 @@ static PyMethodDef posix_methods[] = {
 #ifdef HAVE_GETPPID\r
     {"getppid",         posix_getppid, METH_NOARGS, posix_getppid__doc__},\r
 #endif /* HAVE_GETPPID */\r
 #ifdef HAVE_GETPPID\r
     {"getppid",         posix_getppid, METH_NOARGS, posix_getppid__doc__},\r
 #endif /* HAVE_GETPPID */\r
-#ifdef HAVE_GETUID\r
-    {"getuid",          posix_getuid, METH_NOARGS, posix_getuid__doc__},\r
-#endif /* HAVE_GETUID */\r
 #ifdef HAVE_GETLOGIN\r
     {"getlogin",        posix_getlogin, METH_NOARGS, posix_getlogin__doc__},\r
 #endif\r
 #ifdef HAVE_GETLOGIN\r
     {"getlogin",        posix_getlogin, METH_NOARGS, posix_getlogin__doc__},\r
 #endif\r
@@ -6933,38 +3814,7 @@ static PyMethodDef posix_methods[] = {
 #endif /* HAVE_PLOCK */\r
 #ifdef HAVE_POPEN\r
     {"popen",           posix_popen, METH_VARARGS, posix_popen__doc__},\r
 #endif /* HAVE_PLOCK */\r
 #ifdef HAVE_POPEN\r
     {"popen",           posix_popen, METH_VARARGS, posix_popen__doc__},\r
-#ifdef MS_WINDOWS\r
-    {"popen2",          win32_popen2, METH_VARARGS},\r
-    {"popen3",          win32_popen3, METH_VARARGS},\r
-    {"popen4",          win32_popen4, METH_VARARGS},\r
-    {"startfile",       win32_startfile, METH_VARARGS, win32_startfile__doc__},\r
-    {"kill",    win32_kill, METH_VARARGS, win32_kill__doc__},\r
-#else\r
-#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
-    {"popen2",          os2emx_popen2, METH_VARARGS},\r
-    {"popen3",          os2emx_popen3, METH_VARARGS},\r
-    {"popen4",          os2emx_popen4, METH_VARARGS},\r
-#endif\r
-#endif\r
 #endif /* HAVE_POPEN */\r
 #endif /* HAVE_POPEN */\r
-#ifdef HAVE_SETUID\r
-    {"setuid",          posix_setuid, METH_VARARGS, posix_setuid__doc__},\r
-#endif /* HAVE_SETUID */\r
-#ifdef HAVE_SETEUID\r
-    {"seteuid",         posix_seteuid, METH_VARARGS, posix_seteuid__doc__},\r
-#endif /* HAVE_SETEUID */\r
-#ifdef HAVE_SETEGID\r
-    {"setegid",         posix_setegid, METH_VARARGS, posix_setegid__doc__},\r
-#endif /* HAVE_SETEGID */\r
-#ifdef HAVE_SETREUID\r
-    {"setreuid",        posix_setreuid, METH_VARARGS, posix_setreuid__doc__},\r
-#endif /* HAVE_SETREUID */\r
-#ifdef HAVE_SETREGID\r
-    {"setregid",        posix_setregid, METH_VARARGS, posix_setregid__doc__},\r
-#endif /* HAVE_SETREGID */\r
-#ifdef HAVE_SETGID\r
-    {"setgid",          posix_setgid, METH_VARARGS, posix_setgid__doc__},\r
-#endif /* HAVE_SETGID */\r
 #ifdef HAVE_SETGROUPS\r
     {"setgroups",       posix_setgroups, METH_O, posix_setgroups__doc__},\r
 #endif /* HAVE_SETGROUPS */\r
 #ifdef HAVE_SETGROUPS\r
     {"setgroups",       posix_setgroups, METH_O, posix_setgroups__doc__},\r
 #endif /* HAVE_SETGROUPS */\r
@@ -7102,18 +3952,6 @@ static PyMethodDef posix_methods[] = {
     {"pathconf",        posix_pathconf, METH_VARARGS, posix_pathconf__doc__},\r
 #endif\r
     {"abort",           posix_abort,      METH_NOARGS,  posix_abort__doc__},\r
     {"pathconf",        posix_pathconf, METH_VARARGS, posix_pathconf__doc__},\r
 #endif\r
     {"abort",           posix_abort,      METH_NOARGS,  posix_abort__doc__},\r
-#ifdef HAVE_SETRESUID\r
-    {"setresuid",       posix_setresuid, METH_VARARGS, posix_setresuid__doc__},\r
-#endif\r
-#ifdef HAVE_SETRESGID\r
-    {"setresgid",       posix_setresgid, METH_VARARGS, posix_setresgid__doc__},\r
-#endif\r
-#ifdef HAVE_GETRESUID\r
-    {"getresuid",       posix_getresuid, METH_NOARGS, posix_getresuid__doc__},\r
-#endif\r
-#ifdef HAVE_GETRESGID\r
-    {"getresgid",       posix_getresgid, METH_NOARGS, posix_getresgid__doc__},\r
-#endif\r
 \r
     {NULL,              NULL}            /* Sentinel */\r
 };\r
 \r
     {NULL,              NULL}            /* Sentinel */\r
 };\r
@@ -7310,34 +4148,11 @@ all_ins(PyObject *d)
 #endif /* EX_NOTFOUND */\r
 \r
 #ifdef HAVE_SPAWNV\r
 #endif /* EX_NOTFOUND */\r
 \r
 #ifdef HAVE_SPAWNV\r
-#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
-    if (ins(d, "P_WAIT", (long)P_WAIT)) return -1;\r
-    if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1;\r
-    if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1;\r
-    if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1;\r
-    if (ins(d, "P_SESSION", (long)P_SESSION)) return -1;\r
-    if (ins(d, "P_DETACH", (long)P_DETACH)) return -1;\r
-    if (ins(d, "P_PM", (long)P_PM)) return -1;\r
-    if (ins(d, "P_DEFAULT", (long)P_DEFAULT)) return -1;\r
-    if (ins(d, "P_MINIMIZE", (long)P_MINIMIZE)) return -1;\r
-    if (ins(d, "P_MAXIMIZE", (long)P_MAXIMIZE)) return -1;\r
-    if (ins(d, "P_FULLSCREEN", (long)P_FULLSCREEN)) return -1;\r
-    if (ins(d, "P_WINDOWED", (long)P_WINDOWED)) return -1;\r
-    if (ins(d, "P_FOREGROUND", (long)P_FOREGROUND)) return -1;\r
-    if (ins(d, "P_BACKGROUND", (long)P_BACKGROUND)) return -1;\r
-    if (ins(d, "P_NOCLOSE", (long)P_NOCLOSE)) return -1;\r
-    if (ins(d, "P_NOSESSION", (long)P_NOSESSION)) return -1;\r
-    if (ins(d, "P_QUOTE", (long)P_QUOTE)) return -1;\r
-    if (ins(d, "P_TILDE", (long)P_TILDE)) return -1;\r
-    if (ins(d, "P_UNRELATED", (long)P_UNRELATED)) return -1;\r
-    if (ins(d, "P_DEBUGDESC", (long)P_DEBUGDESC)) return -1;\r
-#else\r
     if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;\r
     if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;\r
     if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;\r
     if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;\r
     if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;\r
     if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;\r
     if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;\r
     if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;\r
     if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;\r
     if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;\r
-#endif\r
 #endif\r
   return 0;\r
 }\r
 #endif\r
   return 0;\r
 }\r