summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-07-24 12:54:17 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-07-24 12:54:17 (GMT)
commit982e9fea0a9c6026b4d176ce136676ab1893e4b2 (patch)
treed05c8868fc779078c5722d7d0c2fa6d180a11060 /Modules/posixmodule.c
parentd22968af17f64ed5883f9cccfed0f0337dc3bc19 (diff)
downloadcpython-982e9fea0a9c6026b4d176ce136676ab1893e4b2.zip
cpython-982e9fea0a9c6026b4d176ce136676ab1893e4b2.tar.gz
cpython-982e9fea0a9c6026b4d176ce136676ab1893e4b2.tar.bz2
Bug #1524310: Properly report errors from FindNextFile in os.listdir.
Will backport to 2.4.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e118237..d968b6c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1862,6 +1862,15 @@ posix_listdir(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
result = FindNextFileW(hFindFile, &wFileData);
Py_END_ALLOW_THREADS
+ /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+ it got to the end of the directory. */
+ if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ Py_DECREF(d);
+ win32_error_unicode("FindNextFileW", wnamebuf);
+ FindClose(hFindFile);
+ free(wnamebuf);
+ return NULL;
+ }
} while (result == TRUE);
if (FindClose(hFindFile) == FALSE) {
@@ -1921,6 +1930,14 @@ posix_listdir(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
result = FindNextFile(hFindFile, &FileData);
Py_END_ALLOW_THREADS
+ /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+ it got to the end of the directory. */
+ if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ Py_DECREF(d);
+ win32_error("FindNextFile", namebuf);
+ FindClose(hFindFile);
+ return NULL;
+ }
} while (result == TRUE);
if (FindClose(hFindFile) == FALSE) {