Commit e359c1e4 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'windows-unused-params'

7ee0dbee Directory: capture the error message
2a118b34 SystemTools: use nullptr in Windows-only code
f69c5cb7

 Directory: return a bool literal on Windows
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !206
parents 6e171887 7ee0dbee
...@@ -121,7 +121,21 @@ bool Directory::Load(const std::string& name, std::string* errorMessage) ...@@ -121,7 +121,21 @@ bool Directory::Load(const std::string& name, std::string* errorMessage)
delete[] buf; delete[] buf;
if (srchHandle == -1) { 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 // Loop through names
...@@ -152,6 +166,20 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name, ...@@ -152,6 +166,20 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name,
delete[] buf; delete[] buf;
if (srchHandle == -1) { 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; return 0;
} }
......
...@@ -244,7 +244,7 @@ inline int Chdir(const std::string& dir) ...@@ -244,7 +244,7 @@ inline int Chdir(const std::string& dir)
return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
} }
inline void Realpath(const std::string& path, std::string& resolved_path, inline void Realpath(const std::string& path, std::string& resolved_path,
std::string* errorMessage = 0) std::string* errorMessage = nullptr)
{ {
std::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); std::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path);
wchar_t* ptemp; wchar_t* ptemp;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment