Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks.

This is a backport of changesets 13e2e44db99d and 525407d89277.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 25330a0..90838c9 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8174,7 +8174,7 @@
     int fds[2];
     int res;
 
-    flags = PyLong_AsLong(arg);
+    flags = _PyLong_AsInt(arg);
     if (flags == -1 && PyErr_Occurred())
         return NULL;