diff options
author | Brad King <brad.king@kitware.com> | 2020-05-18 12:51:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-05-18 12:51:33 (GMT) |
commit | ef4d992b5483403ea63df33fef1787b2c84f9b7e (patch) | |
tree | fcbbfb350206ed3a0c88c4180d834fee85fc0f4a /Source/kwsys/Directory.cxx | |
parent | 6c4bfb6e7f4998d2a163f78bde1dd1b982947c0a (diff) | |
parent | 8fd4c19e1b39efa6912321a72ac12a1c0121264e (diff) | |
download | CMake-ef4d992b5483403ea63df33fef1787b2c84f9b7e.zip CMake-ef4d992b5483403ea63df33fef1787b2c84f9b7e.tar.gz CMake-ef4d992b5483403ea63df33fef1787b2c84f9b7e.tar.bz2 |
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream
* upstream-KWSys:
KWSys 2020-05-18 (146f6b36)
Diffstat (limited to 'Source/kwsys/Directory.cxx')
-rw-r--r-- | Source/kwsys/Directory.cxx | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index d640948..be9158e 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -103,7 +103,7 @@ void Directory::Clear() namespace KWSYS_NAMESPACE { -bool Directory::Load(const std::string& name) +bool Directory::Load(const std::string& name, std::string* errorMessage) { this->Clear(); # if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__) @@ -146,7 +146,8 @@ bool Directory::Load(const std::string& name) return _findclose(srchHandle) != -1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) +unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, + std::string* errorMessage) { # if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__) // Older Visual C++ and Embarcadero compilers. @@ -192,6 +193,8 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) # include <sys/types.h> # include <dirent.h> +# include <errno.h> +# include <string.h> // PGI with glibc has trouble with dirent and large file support: // http://www.pgroup.com/userforum/viewtopic.php? @@ -209,29 +212,46 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) namespace KWSYS_NAMESPACE { -bool Directory::Load(const std::string& name) +bool Directory::Load(const std::string& name, std::string* errorMessage) { this->Clear(); + errno = 0; DIR* dir = opendir(name.c_str()); if (!dir) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } return false; } + errno = 0; for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) { this->Internal->Files.emplace_back(d->d_name); } + if (errno != 0) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } + return false; + } + this->Internal->Path = name; closedir(dir); return true; } -unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) +unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, + std::string* errorMessage) { + errno = 0; DIR* dir = opendir(name.c_str()); if (!dir) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } return 0; } @@ -239,6 +259,13 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name) for (kwsys_dirent* d = readdir(dir); d; d = readdir(dir)) { count++; } + if (errno != 0) { + if (errorMessage != nullptr) { + *errorMessage = std::string(strerror(errno)); + } + return false; + } + closedir(dir); return count; } |