diff options
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index dcb79f7..0c80319 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -7,9 +7,10 @@ #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" -#include "cmsys/String.hxx" + #include <algorithm> #include <assert.h> +#include <ctype.h> #include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> @@ -207,16 +208,20 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, cmSystemTools::MakeDirectory(dir); mode_t mode = 0; + bool writable = false; // Set permissions to writable if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) { - cmSystemTools::SetPermissions(fileName.c_str(), #if defined(_MSC_VER) || defined(__MINGW32__) - mode | S_IWRITE + writable = mode & S_IWRITE; + mode_t newMode = mode | S_IWRITE; #else - mode | S_IWUSR | S_IWGRP + writable = mode & S_IWUSR; + mode_t newMode = mode | S_IWUSR | S_IWGRP; #endif - ); + if (!writable) { + cmSystemTools::SetPermissions(fileName.c_str(), newMode); + } } // If GetPermissions fails, pretend like it is ok. File open will fail if // the file is not writable @@ -241,7 +246,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, return false; } file.close(); - if (mode) { + if (mode && !writable) { cmSystemTools::SetPermissions(fileName.c_str(), mode); } return true; @@ -609,8 +614,8 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) continue; } - if ((c >= 0x20 && c < 0x7F) || c == '\t' || - (c == '\n' && newline_consume)) { + if (c >= 0 && c <= 0xFF && + (isprint(c) || c == '\t' || (c == '\n' && newline_consume))) { // This is an ASCII character that may be part of a string. // Cast added to avoid compiler warning. Cast is ok because // c is guaranteed to fit in char by the above if... @@ -658,7 +663,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) // The current line has been terminated. Check if the current // string matches the requirements. The length may now be as // low as zero since blank lines are allowed. - if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { + if (s.length() >= minlen && (!have_regex || regex.find(s))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -674,7 +679,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) // string matches the requirements. We require that the length // be at least one no matter what the user specified. if (s.length() >= minlen && !s.empty() && - (!have_regex || regex.find(s.c_str()))) { + (!have_regex || regex.find(s))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -691,7 +696,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) if (maxlen > 0 && s.size() == maxlen) { // Terminate a string if the maximum length is reached. - if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { + if (s.length() >= minlen && (!have_regex || regex.find(s))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -707,7 +712,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) // input file or the input size limit. Check if the current string // matches the requirements. if ((!limit_count || strings.size() < limit_count) && !s.empty() && - s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { + s.length() >= minlen && (!have_regex || regex.find(s))) { output_size += static_cast<int>(s.size()) + 1; if (limit_output < 0 || output_size < limit_output) { strings.push_back(s); @@ -2484,11 +2489,11 @@ bool cmFileCommand::HandleCMakePathCommand( #else char pathSep = ':'; #endif - std::vector<cmsys::String> path = cmSystemTools::SplitString(*i, pathSep); + std::vector<std::string> path = cmSystemTools::SplitString(*i, pathSep); i++; const char* var = i->c_str(); std::string value; - for (std::vector<cmsys::String>::iterator j = path.begin(); j != path.end(); + for (std::vector<std::string>::iterator j = path.begin(); j != path.end(); ++j) { if (j != path.begin()) { value += ";"; @@ -2498,7 +2503,7 @@ bool cmFileCommand::HandleCMakePathCommand( } else { *j = cmSystemTools::ConvertToOutputPath(*j); // remove double quotes in the path - cmsys::String& s = *j; + std::string& s = *j; if (s.size() > 1 && s[0] == '\"' && s[s.size() - 1] == '\"') { s = s.substr(1, s.size() - 2); |