Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c £¨revision 74624£© +++ Modules/posixmodule.c £¨working copy£© @@ -2001,8 +2005,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; @@ -2034,15 +2041,23 @@ #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 + } while ((res == null) && errno = ERANGE) Py_END_ALLOW_THREADS 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 */