summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/Directory.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-08 18:32:35 (GMT)
committerBrad King <brad.king@kitware.com>2021-03-08 18:32:35 (GMT)
commit4d86c907f30424e6dc83827f1cd405e34abeef71 (patch)
tree5700cee32293bc02300100c571aa928a6e8c5aaa /Source/kwsys/Directory.cxx
parent1982264c17233c274879ad1b688064f0624ded1f (diff)
parent9e556829c8fd2e78860e798f454f90dc1160dd20 (diff)
downloadCMake-4d86c907f30424e6dc83827f1cd405e34abeef71.zip
CMake-4d86c907f30424e6dc83827f1cd405e34abeef71.tar.gz
CMake-4d86c907f30424e6dc83827f1cd405e34abeef71.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream * upstream-KWSys: KWSys 2021-03-08 (5bfba5e1)
Diffstat (limited to 'Source/kwsys/Directory.cxx')
-rw-r--r--Source/kwsys/Directory.cxx30
1 files changed, 29 insertions, 1 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index 0c2190a..e70d4e8 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/kwsys/Directory.cxx
@@ -121,7 +121,21 @@ bool Directory::Load(const std::string& name, std::string* errorMessage)
delete[] buf;
if (srchHandle == -1) {
- return 0;
+ if (errorMessage) {
+ if (unsigned int errorId = GetLastError()) {
+ LPSTR message = nullptr;
+ DWORD size = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, errorId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&message, 0, nullptr);
+ *errorMessage = std::string(message, size);
+ LocalFree(message);
+ } else {
+ *errorMessage = "Unknown error.";
+ }
+ }
+ return false;
}
// Loop through names
@@ -152,6 +166,20 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name,
delete[] buf;
if (srchHandle == -1) {
+ if (errorMessage) {
+ if (unsigned int errorId = GetLastError()) {
+ LPSTR message = nullptr;
+ DWORD size = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, errorId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&message, 0, nullptr);
+ *errorMessage = std::string(message, size);
+ LocalFree(message);
+ } else {
+ *errorMessage = "Unknown error.";
+ }
+ }
return 0;
}