summaryrefslogtreecommitdiff
path: root/Source/kwsys
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-08 13:32:35 -0500
committerBrad King <brad.king@kitware.com>2021-03-08 13:32:35 -0500
commit4d86c907f30424e6dc83827f1cd405e34abeef71 (patch)
tree5700cee32293bc02300100c571aa928a6e8c5aaa /Source/kwsys
parent1982264c17233c274879ad1b688064f0624ded1f (diff)
parent9e556829c8fd2e78860e798f454f90dc1160dd20 (diff)
downloadcmake-4d86c907f30424e6dc83827f1cd405e34abeef71.tar.gz
Merge branch 'upstream-KWSys' into update-kwsys
# By KWSys Upstream * upstream-KWSys: KWSys 2021-03-08 (5bfba5e1)
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/Directory.cxx30
-rw-r--r--Source/kwsys/Glob.hxx.in7
-rw-r--r--Source/kwsys/SystemTools.cxx17
-rw-r--r--Source/kwsys/SystemTools.hxx.in11
4 files changed, 50 insertions, 15 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index 0c2190aee5..e70d4e8688 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;
}
diff --git a/Source/kwsys/Glob.hxx.in b/Source/kwsys/Glob.hxx.in
index e8474e2001..fd39775417 100644
--- a/Source/kwsys/Glob.hxx.in
+++ b/Source/kwsys/Glob.hxx.in
@@ -54,6 +54,9 @@ public:
Glob();
~Glob();
+ Glob(const Glob&) = delete;
+ void operator=(const Glob&) = delete;
+
//! Find all files that match the pattern.
bool FindFiles(const std::string& inexpr, GlobMessages* messages = nullptr);
@@ -124,10 +127,6 @@ protected:
std::vector<std::string> VisitedSymlinks;
bool ListDirs;
bool RecurseListDirs;
-
-private:
- Glob(const Glob&) = delete;
- void operator=(const Glob&) = delete;
};
} // namespace @KWSYS_NAMESPACE@
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 6144d9c04d..cf04799776 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -244,7 +244,7 @@ inline int Chdir(const std::string& dir)
return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
}
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);
wchar_t* ptemp;
@@ -2273,11 +2273,8 @@ bool SystemTools::TextFilesDiffer(const std::string& path1,
return false;
}
-/**
- * Blockwise copy source to destination file
- */
-static bool CopyFileContentBlockwise(const std::string& source,
- const std::string& destination)
+bool SystemTools::CopyFileContentBlockwise(const std::string& source,
+ const std::string& destination)
{
// Open files
kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
@@ -2341,8 +2338,8 @@ static bool CopyFileContentBlockwise(const std::string& source,
* - The underlying filesystem does not support file cloning
* - An unspecified error occurred
*/
-static bool CloneFileContent(const std::string& source,
- const std::string& destination)
+bool SystemTools::CloneFileContent(const std::string& source,
+ const std::string& destination)
{
#if defined(__linux) && defined(FICLONE)
int in = open(source.c_str(), O_RDONLY);
@@ -2410,9 +2407,9 @@ bool SystemTools::CopyFileAlways(const std::string& source,
SystemTools::MakeDirectory(destination_dir);
- if (!CloneFileContent(source, real_destination)) {
+ if (!SystemTools::CloneFileContent(source, real_destination)) {
// if cloning did not succeed, fall back to blockwise copy
- if (!CopyFileContentBlockwise(source, real_destination)) {
+ if (!SystemTools::CopyFileContentBlockwise(source, real_destination)) {
return false;
}
}
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 74dc176514..a7b1288733 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -578,6 +578,17 @@ public:
const std::string& path2);
/**
+ * Blockwise copy source to destination file
+ */
+ static bool CopyFileContentBlockwise(const std::string& source,
+ const std::string& destination);
+ /**
+ * Clone the source file to the destination file
+ */
+ static bool CloneFileContent(const std::string& source,
+ const std::string& destination);
+
+ /**
* Return true if the two files are the same file
*/
static bool SameFile(const std::string& file1, const std::string& file2);