浏览代码

Fix error handling in readdir in minirent.h

rexim 4 年之前
父节点
当前提交
9c963a7729
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      minirent.h

+ 6 - 3
minirent.h

@@ -82,9 +82,12 @@ struct dirent *readdir(DIR *dirp)
         dirp->dirent = (struct dirent*)calloc(1, sizeof(struct dirent));
         dirp->dirent = (struct dirent*)calloc(1, sizeof(struct dirent));
     } else {
     } else {
         if(!FindNextFile(dirp->hFind, &dirp->data)) {
         if(!FindNextFile(dirp->hFind, &dirp->data)) {
-            // TODO: readdir should set errno accordingly on FindFirstFile fail
-            // https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
-            errno = ENOSYS;
+            if (GetLastError() != ERROR_NO_MORE_FILES) {
+                // TODO: readdir should set errno accordingly on FindFirstFile fail
+                // https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
+                errno = ENOSYS;
+            }
+
             return NULL;
             return NULL;
         }
         }
     }
     }