Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 82845) +++ Modules/posixmodule.c (working copy) @@ -1957,9 +1957,30 @@ "getcwd() -> path\n\n\ Return a string representing the current working directory."); +#ifdef PATH_MAX static PyObject * posix_getcwd(PyObject *self, PyObject *noargs) { + char buf[PATH_MAX+2]; + char *res; + + Py_BEGIN_ALLOW_THREADS +#if defined(PYOS_OS2) && defined(PYCC_GCC) + res = _getcwd2(buf, sizeof buf); +#else + res = getcwd(buf, sizeof buf); +#endif + Py_END_ALLOW_THREADS + + if (res == NULL) + return posix_error(); + + return PyString_FromString(buf); +} +#else +static PyObject * +posix_getcwd(PyObject *self, PyObject *noargs) +{ int bufsize_incr = 1024; int bufsize = 0; char *tmpbuf = NULL; @@ -1993,6 +2014,7 @@ return dynamic_return; } +#endif /* PATH_MAX */ #ifdef Py_USING_UNICODE PyDoc_STRVAR(posix_getcwdu__doc__, Index: Lib/test/test_posix.py =================================================================== --- Lib/test/test_posix.py (revision 82816) +++ Lib/test/test_posix.py (working copy) @@ -347,6 +347,8 @@ os.getcwd() if current_path_length < 1027: _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) + except OSError: + pass finally: os.chdir('..') os.rmdir(dirname)