Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 74738) +++ Modules/posixmodule.c (working copy) @@ -2001,9 +2013,11 @@ static PyObject * posix_getcwdu(PyObject *self, PyObject *noargs) { - char buf[1026]; - char *res; - + int bufsize_incr = 1024; + int bufsize = 0; + char *tmpbuf = null; + char *res = null; + PyObject *dynamic_return; #ifdef MS_WINDOWS DWORD len; wchar_t wbuf[1026]; @@ -2034,15 +2048,27 @@ #endif /* MS_WINDOWS */ Py_BEGIN_ALLOW_THREADS + do { + bufsize = bufsize + bufsize_incr; + tmpbuf = malloc(bufsize); + if(tmpbuf == null) + break; #if defined(PYOS_OS2) && defined(PYCC_GCC) - res = _getcwd2(buf, sizeof buf); + res = _getcwd2(tmpbuf, bufsize); #else - res = getcwd(buf, sizeof buf); + res = getcwd(tmpbuf, bufsize); #endif + if (res == NULL) { + free(tmpbuf); + } + } while ((res == NULL) && (errno == ERANGE)); Py_END_ALLOW_THREADS - if (res == NULL) + if (res == NULL) { return posix_error(); - return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"strict"); + } + dynamic_return = PyUnicode_Decode(tmpbuf, strlen(tmpbuf), Py_FileSystemDefaultEncoding,"strict"); + free(tmpbuf); + return dynamic_return; } #endif /* Py_USING_UNICODE */ #endif /* HAVE_GETCWD */