summaryrefslogtreecommitdiffstats
path: root/winsup/mingw/mingwex/dirent.c
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/mingw/mingwex/dirent.c')
-rw-r--r--winsup/mingw/mingwex/dirent.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/winsup/mingw/mingwex/dirent.c b/winsup/mingw/mingwex/dirent.c
index e3c81e1b2..bef2222cb 100644
--- a/winsup/mingw/mingwex/dirent.c
+++ b/winsup/mingw/mingwex/dirent.c
@@ -165,7 +165,12 @@ _treaddir (_TDIR * dirp)
/* Get the next search entry. */
if (_tfindnext (dirp->dd_handle, &(dirp->dd_dta)))
{
- /* We are off the end or otherwise error. */
+ /* We are off the end or otherwise error.
+ _findnext sets errno to ENOENT if no more file
+ Undo this. */
+ DWORD winerr = GetLastError();
+ if (winerr == ERROR_NO_MORE_FILES)
+ errno = 0;
_findclose (dirp->dd_handle);
dirp->dd_handle = -1;
dirp->dd_stat = -1;