summaryrefslogtreecommitdiffstats
path: root/SystemTools.cxx
diff options
context:
space:
mode:
authorKWSys Upstream <kwrobot@kitware.com>2020-05-13 10:38:50 (GMT)
committerBrad King <brad.king@kitware.com>2020-05-13 11:08:19 (GMT)
commit3674f6a47000db2b519a44062b8ce46db4f12691 (patch)
tree15af3e749b4f625d2733ea204fe8e65c8567af19 /SystemTools.cxx
parente833e660efe92f6249ac87c09c7263cf2d3d43b3 (diff)
downloadCMake-3674f6a47000db2b519a44062b8ce46db4f12691.zip
CMake-3674f6a47000db2b519a44062b8ce46db4f12691.tar.gz
CMake-3674f6a47000db2b519a44062b8ce46db4f12691.tar.bz2
KWSys 2020-05-13 (d4da6980)
Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit d4da69800d9103a7d3654f9428386a914ba280f2 (master). Upstream Shortlog ----------------- Sean McBride (5): c58d4b47 SystemTools: On Windows, strip 'e' from Fopen mode cb541c31 Auto-fixed various clang-tidy warnings 2c179921 Applied clang-tidy modernize-deprecated-headers 775296c8 Applied clang-tidy bugprone-suspicious-string-compare fixes a19f0ac6 Fixed clang -Wstrict-prototypes warning
Diffstat (limited to 'SystemTools.cxx')
-rw-r--r--SystemTools.cxx37
1 files changed, 21 insertions, 16 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx
index 3a6ceec..a6d210f 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -24,6 +24,7 @@
#include KWSYS_HEADER(Encoding.h)
#include KWSYS_HEADER(Encoding.hxx)
+#include <algorithm>
#include <fstream>
#include <iostream>
#include <set>
@@ -49,15 +50,15 @@
# pragma set woff 1375 /* base class destructor not virtual */
#endif
-#include <ctype.h>
-#include <errno.h>
+#include <cctype>
+#include <cerrno>
#ifdef __QNX__
# include <malloc.h> /* for malloc/free on QNX */
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
#if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__)
# include <strings.h> /* for strcasecmp */
@@ -69,7 +70,7 @@
// support for realpath call
#ifndef _WIN32
-# include <limits.h>
+# include <climits>
# include <pwd.h>
# include <sys/ioctl.h>
# include <sys/time.h>
@@ -80,7 +81,7 @@
# include <sys/param.h>
# include <termios.h>
# endif
-# include <signal.h> /* sigprocmask */
+# include <csignal> /* sigprocmask */
#endif
#ifdef __linux
@@ -892,8 +893,12 @@ const char* SystemTools::GetExecutableExtension()
FILE* SystemTools::Fopen(const std::string& file, const char* mode)
{
#ifdef _WIN32
+ // Remove any 'e', which is supported on UNIX, but not Windows.
+ std::wstring trimmedMode = Encoding::ToWide(mode);
+ trimmedMode.erase(std::remove(trimmedMode.begin(), trimmedMode.end(), L'e'),
+ trimmedMode.end());
return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(),
- Encoding::ToWide(mode).c_str());
+ trimmedMode.c_str());
#else
return fopen(file.c_str(), mode);
#endif
@@ -2113,7 +2118,7 @@ std::string SystemTools::ConvertToUnixOutputPath(const std::string& path)
ret.erase(pos, 1);
}
// escape spaces and () in the path
- if (ret.find_first_of(" ") != std::string::npos) {
+ if (ret.find_first_of(' ') != std::string::npos) {
std::string result;
char lastch = 1;
for (const char* ch = ret.c_str(); *ch != '\0'; ++ch) {
@@ -2511,8 +2516,8 @@ bool SystemTools::CopyADirectory(const std::string& source,
return false;
}
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) {
- if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") &&
- strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..")) {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") != 0 &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..") != 0) {
std::string fullPath = source;
fullPath += "/";
fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
@@ -2674,8 +2679,8 @@ bool SystemTools::RemoveADirectory(const std::string& source)
dir.Load(source);
size_t fileNum;
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) {
- if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") &&
- strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..")) {
+ if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") != 0 &&
+ strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..") != 0) {
std::string fullPath = source;
fullPath += "/";
fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
@@ -3153,7 +3158,7 @@ bool SystemTools::SplitProgramPath(const std::string& in_name,
SystemTools::ConvertToUnixSlashes(dir);
if (!SystemTools::FileIsDirectory(dir)) {
- std::string::size_type slashPos = dir.rfind("/");
+ std::string::size_type slashPos = dir.rfind('/');
if (slashPos != std::string::npos) {
file = dir.substr(slashPos + 1);
dir.resize(slashPos);
@@ -3711,7 +3716,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename)
std::string fn = filename;
SystemTools::ConvertToUnixSlashes(fn);
- std::string::size_type slash_pos = fn.rfind("/");
+ std::string::size_type slash_pos = fn.rfind('/');
if (slash_pos == 0) {
return "/";
}