Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (révision 83115) +++ Modules/posixmodule.c (copie de travail) @@ -2207,8 +2207,11 @@ static PyObject * posix_getcwd(int use_bytes) { - char buf[1026]; - char *res; + const int bufsize_incr = 1024; + int bufsize = 0; + char *buf = NULL, *oldbuf; + char *res = NULL; + PyObject *path; #ifdef MS_WINDOWS if (!use_bytes) { @@ -2242,17 +2245,37 @@ #endif Py_BEGIN_ALLOW_THREADS + do { + bufsize = bufsize + bufsize_incr; + oldbuf = buf; + buf = PyMem_Realloc(oldbuf, bufsize); + if (buf == NULL) { + if (oldbuf != NULL) + PyMem_Free(oldbuf); + break; + } + #if defined(PYOS_OS2) && defined(PYCC_GCC) - res = _getcwd2(buf, sizeof buf); + res = _getcwd2(buf, bufsize); #else - res = getcwd(buf, sizeof buf); + res = getcwd(buf, bufsize); #endif + } while ((res == NULL) && (errno == ERANGE)); Py_END_ALLOW_THREADS - if (res == NULL) + + if (buf == NULL) + return PyErr_NoMemory(); + if (res == NULL) { + PyMem_Free(buf); return posix_error(); + } + if (use_bytes) - return PyBytes_FromStringAndSize(buf, strlen(buf)); - return PyUnicode_DecodeFSDefault(buf); + path = PyBytes_FromStringAndSize(buf, strlen(buf)); + else + path = PyUnicode_DecodeFSDefault(buf); + PyMem_Free(buf); + return path; } PyDoc_STRVAR(posix_getcwd__doc__,