Index: Lib/test/test_posix.py =================================================================== --- Lib/test/test_posix.py (revision 80186) +++ Lib/test/test_posix.py (working copy) @@ -262,10 +262,15 @@ posix.chdir(os.curdir) self.assertRaises(OSError, posix.chdir, test_support.TESTFN) - def test_lsdir(self): - if hasattr(posix, 'lsdir'): - self.assertIn(test_support.TESTFN, posix.lsdir(os.curdir)) + def test_listdir(self): + if hasattr(posix, 'listdir'): + self.assertTrue(test_support.TESTFN in posix.listdir(os.curdir)) + def test_listdir_default(self): + # When listdir is called without argument, it's the same as listdir(os.curdir) + if hasattr(posix, 'listdir'): + self.assertTrue(test_support.TESTFN in posix.listdir()) + def test_access(self): if hasattr(posix, 'access'): self.assertTrue(posix.access(test_support.TESTFN, os.R_OK)) Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 80186) +++ Modules/posixmodule.c (working copy) @@ -2086,18 +2086,25 @@ char *bufptr = namebuf; Py_ssize_t len = sizeof(namebuf)-5; /* only claim to have space for MAX_PATH */ - PyObject *po; - if (PyArg_ParseTuple(args, "U:listdir", &po)) { + PyObject *po = NULL; + if (PyArg_ParseTuple(args, "|U:listdir", &po)) { WIN32_FIND_DATAW wFileData; - Py_UNICODE *wnamebuf; + Py_UNICODE *wnamebuf, *po_wchars; + + if (po == NULL) { // Default arg: "." + po_wchars = L"."; + len = 1; + } else { + po_wchars = PyUnicode_AS_UNICODE(po); + len = PyUnicode_GET_SIZE(po); + } /* Overallocate for \\*.*\0 */ - len = PyUnicode_GET_SIZE(po); wnamebuf = malloc((len + 5) * sizeof(wchar_t)); if (!wnamebuf) { PyErr_NoMemory(); return NULL; } - wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po)); + wcscpy(wnamebuf, po_wchars); if (len > 0) { Py_UNICODE wch = wnamebuf[len-1]; if (wch != L'/' && wch != L'\\' && wch != L':') @@ -2304,12 +2311,16 @@ int arg_is_unicode = 1; errno = 0; - if (!PyArg_ParseTuple(args, "U:listdir", &v)) { + if (!PyArg_ParseTuple(args, "|U:listdir", &v)) { arg_is_unicode = 0; PyErr_Clear(); } - if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name)) + if (!PyArg_ParseTuple(args, "|et:listdir", Py_FileSystemDefaultEncoding, &name)) return NULL; + if (name == NULL) { // Default arg: "." + name = (char *)PyMem_Malloc(2); // "." + \0 + strcpy(name, "."); + } if ((dirp = opendir(name)) == NULL) { return posix_error_with_allocated_filename(name); }