summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/kwsys/Directory.cxx25
1 files changed, 16 insertions, 9 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index 5141d4519..804990992 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/kwsys/Directory.cxx
@@ -180,6 +180,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
#include <sys/types.h>
#include <dirent.h>
+#include <stdio.h>
+#include <malloc.h>
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
@@ -201,17 +203,22 @@ bool Directory::Load(const std::string& name)
{
this->Clear();
- DIR* dir = opendir(name.c_str());
-
- if (!dir) {
+ struct dirent** namelist;
+ int num_entries = scandir(name, &namelist, NULL, alphasort);
+ if(num_entries == -1)
+ {
+ printf("name=%s\n", name);
+ perror("scandir");
return 0;
- }
-
- for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) {
- this->Internal->Files.push_back(d->d_name);
- }
+ }
+
+ for( int i = 0; i < num_entries; ++i )
+ {
+ this->Internal->Files.push_back(namelist[i]->d_name);
+ free(namelist[i]);
+ }
+ free(namelist);
this->Internal->Path = name;
- closedir(dir);
return 1;
}