Files
MINGW-packages/mingw-w64-python3/0730-mingw-fix-ncurses-module.patch
2014-10-11 14:46:25 +01:00

100 lines
2.6 KiB
Diff

diff -urN a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c 2014-10-11 14:22:39.496856600 +0100
+++ b/Modules/_cursesmodule.c 2014-10-11 14:22:41.210954600 +0100
@@ -125,6 +125,10 @@
#include <langinfo.h>
#endif
+#ifdef __MINGW32__
+#include <windows.h>
+#endif
+
#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
typedef chtype attr_t; /* No attr_t type is available */
@@ -1772,10 +1776,14 @@
/* We have to simulate this by writing to a temporary FILE*,
then reading back, then writing to the argument stream. */
char fn[100];
+#ifndef MS_WINDOWS
int fd = -1;
+#endif
FILE *fp = NULL;
PyObject *res = NULL;
+#ifndef MS_WINDOWS
+/* Even on unix /tmp may not exist and the program must prefer $TMPDIR ! */
strcpy(fn, "/tmp/py.curses.putwin.XXXXXX");
fd = mkstemp(fn);
if (fd < 0)
@@ -1783,6 +1791,14 @@
if (_Py_set_inheritable(fd, 0, NULL) < 0)
goto exit;
fp = fdopen(fd, "wb+");
+#else
+ strcpy(fn, "py.curses.putwin.XXXXXX");
+ _mktemp(fn);
+ if (*fn == 0)
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ fp = fopen(fn, "wb+");
+#endif
+
if (fp == NULL) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
goto exit;
@@ -1807,8 +1823,10 @@
exit:
if (fp != NULL)
fclose(fp);
+ #ifndef MS_WINDOWS
else if (fd != -1)
close(fd);
+ #endif
remove(fn);
return res;
}
@@ -2331,7 +2349,9 @@
PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
{
char fn[100];
+#ifndef MS_WINDOWS
int fd = -1;
+#endif
FILE *fp = NULL;
PyObject *data;
size_t datalen;
@@ -2341,6 +2361,8 @@
PyCursesInitialised;
+#ifndef MS_WINDOWS
+/* Even on unix /tmp may not exist and the program must prefer $TMPDIR ! */
strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
fd = mkstemp(fn);
if (fd < 0)
@@ -2348,6 +2370,13 @@
if (_Py_set_inheritable(fd, 0, NULL) < 0)
goto error;
fp = fdopen(fd, "wb+");
+#else
+ strcpy(fn, "py.curses.getwin.XXXXXX");
+ _mktemp(fn);
+ if (*fn == 0)
+ return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
+ fp = fopen(fn, "wb+");
+#endif
if (fp == NULL) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
goto error;
@@ -2382,8 +2411,10 @@
error:
if (fp != NULL)
fclose(fp);
+ #ifndef MS_WINDOWS
else if (fd != -1)
close(fd);
+ #endif
remove(fn);
return res;
}