Blob Blame History Raw
Index: doxygen-1.10.0/deps/filesystem/filesystem.hpp
===================================================================
--- doxygen-1.10.0.orig/deps/filesystem/filesystem.hpp
+++ doxygen-1.10.0/deps/filesystem/filesystem.hpp
@@ -5700,12 +5700,13 @@ public:
     impl(const path& path, directory_options options)
         : _base(path)
         , _options(options)
-        , _dir(nullptr)
+        , _namelist(nullptr)
+        , _namelisti(-1)
         , _entry(nullptr)
     {
         if (!path.empty()) {
-            do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR);
-            if (!_dir) {
+            _namelisti = _namelistn = ::scandir(path.native().c_str(), &_namelist, NULL, alphasort);
+            if (_namelistn == -1) {
                 auto error = errno;
                 _base = filesystem::path();
                 if ((error != EACCES && error != EPERM) || (options & directory_options::skip_permission_denied) == directory_options::none) {
@@ -5720,19 +5721,23 @@ public:
     impl(const impl& other) = delete;
     ~impl()
     {
-        if (_dir) {
-            ::closedir(_dir);
+        if (_namelist) {
+            for (int i=_namelistn-1; i>=0; i--) {
+               free(_namelist[i]);
+            }
+            free(_namelist);
+            _namelist = nullptr;
         }
     }
     void increment(std::error_code& ec)
     {
-        if (_dir) {
+        if (_namelist) {
             bool skip;
             do {
                 skip = false;
                 errno = 0;
-                do { _entry = ::readdir(_dir); } while(errno == EINTR);
-                if (_entry) {
+                if (_namelisti > 0 ) {
+                    _entry = _namelist[--_namelisti];
                     _dir_entry._path = _base;
                     _dir_entry._path.append_name(_entry->d_name);
                     copyToDirEntry();
@@ -5742,8 +5747,11 @@ public:
                     }
                 }
                 else {
-                    ::closedir(_dir);
-                    _dir = nullptr;
+                    for (int i=_namelistn-1; i>=0; i--) {
+                        free(_namelist[i]);
+                    }
+                    free(_namelist);
+                    _namelist = nullptr;
                     _dir_entry._path.clear();
                     if (errno && errno != EINTR) {
                         ec = detail::make_system_error();
@@ -5772,7 +5780,9 @@ public:
     }
     path _base;
     directory_options _options;
-    DIR* _dir;
+    int _namelisti;
+    int _namelistn;
+    struct dirent **_namelist;
     struct ::dirent* _entry;
     directory_entry _dir_entry;
     std::error_code _ec;