Issue #12196: Add pipe2() to the os module.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index add3b35..e529afd 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6547,6 +6547,31 @@
}
#endif /* HAVE_PIPE */
+#ifdef HAVE_PIPE2
+PyDoc_STRVAR(posix_pipe2__doc__,
+"pipe2(flags=0) -> (read_end, write_end)\n\n\
+Create a pipe with flags set atomically.\
+flags is optional and can be constructed by ORing together zero or more\n\
+of these values: O_NONBLOCK, O_CLOEXEC.\n\
+");
+
+static PyObject *
+posix_pipe2(PyObject *self, PyObject *args)
+{
+ int flags = 0;
+ int fds[2];
+ int res;
+
+ if (!PyArg_ParseTuple(args, "|i:pipe2", &flags))
+ return NULL;
+
+ res = pipe2(fds, flags);
+ if (res != 0)
+ return posix_error();
+ return Py_BuildValue("(ii)", fds[0], fds[1]);
+}
+#endif /* HAVE_PIPE2 */
+
#ifdef HAVE_WRITEV
PyDoc_STRVAR(posix_writev__doc__,
"writev(fd, buffers) -> byteswritten\n\n\
@@ -9441,6 +9466,9 @@
#ifdef HAVE_PIPE
{"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__},
#endif
+#ifdef HAVE_PIPE2
+ {"pipe2", posix_pipe2, METH_VARARGS, posix_pipe2__doc__},
+#endif
#ifdef HAVE_MKFIFO
{"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
#endif