diff options
Diffstat (limited to 'Source/kwsys/Directory.cxx')
-rw-r--r-- | Source/kwsys/Directory.cxx | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index b88474781..c16b9139b 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -190,6 +190,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) #include <sys/types.h> #include <dirent.h> +#include <stdio.h> +#include <malloc.h> /* There is a problem with the Portland compiler, large file support and glibc/Linux system headers: @@ -211,19 +213,23 @@ bool Directory::Load(const char* name) { return 0; } - DIR* dir = opendir(name); - 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 (dirent* d = readdir(dir); d; d = readdir(dir) ) + + for( int i = 0; i < num_entries; ++i ) { - this->Internal->Files.push_back(d->d_name); + this->Internal->Files.push_back(namelist[i]->d_name); + free(namelist[i]); } + free(namelist); this->Internal->Path = name; - closedir(dir); return 1; } |