diff -Naur Python-3.6.5-orig/Modules/_cursesmodule.c Python-3.6.5/Modules/_cursesmodule.c --- Python-3.6.5-orig/Modules/_cursesmodule.c 2018-03-28 12:19:31.000000000 +0300 +++ Python-3.6.5/Modules/_cursesmodule.c 2018-04-16 09:54:27.146677000 +0300 @@ -125,6 +125,10 @@ #include #endif +#ifdef __MINGW32__ +#include +#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 */ @@ -1748,10 +1752,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) @@ -1759,6 +1767,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; @@ -1783,8 +1799,10 @@ exit: if (fp != NULL) fclose(fp); + #ifndef MS_WINDOWS else if (fd != -1) close(fd); + #endif remove(fn); return res; } @@ -2324,7 +2342,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; @@ -2334,6 +2354,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) @@ -2341,6 +2363,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; @@ -2375,8 +2404,10 @@ error: if (fp != NULL) fclose(fp); + #ifndef MS_WINDOWS else if (fd != -1) close(fd); + #endif remove(fn); return res; }