cmSystemTools: More methods accept std::string params

This commit is contained in:
Vitaly Stakhovsky
2019-02-11 18:11:59 -05:00
parent 8a1d25afdf
commit 080a79ca4a
7 changed files with 78 additions and 74 deletions
+15 -12
View File
@@ -897,7 +897,7 @@ std::string cmSystemTools::PrintSingleCommand(
}
bool cmSystemTools::DoesFileExistWithExtensions(
const char* name, const std::vector<std::string>& headerExts)
const std::string& name, const std::vector<std::string>& headerExts)
{
std::string hname;
@@ -912,9 +912,9 @@ bool cmSystemTools::DoesFileExistWithExtensions(
return false;
}
std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
const char* directory,
const char* toplevel)
std::string cmSystemTools::FileExistsInParentDirectories(
const std::string& fname, const std::string& directory,
const std::string& toplevel)
{
std::string file = fname;
cmSystemTools::ConvertToUnixSlashes(file);
@@ -926,7 +926,7 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
if (cmSystemTools::FileExists(path)) {
return path;
}
if (dir.size() < strlen(toplevel)) {
if (dir.size() < toplevel.size()) {
break;
}
prevDir = dir;
@@ -2081,7 +2081,8 @@ void cmSystemTools::DoNotInheritStdPipes()
#endif
}
bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
bool cmSystemTools::CopyFileTime(const std::string& fromFile,
const std::string& toFile)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemToolsWindowsHandle hFrom = CreateFileW(
@@ -2102,14 +2103,14 @@ bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
return SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite) != 0;
#else
struct stat fromStat;
if (stat(fromFile, &fromStat) < 0) {
if (stat(fromFile.c_str(), &fromStat) < 0) {
return false;
}
struct utimbuf buf;
buf.actime = fromStat.st_atime;
buf.modtime = fromStat.st_mtime;
return utime(toFile, &buf) >= 0;
return utime(toFile.c_str(), &buf) >= 0;
#endif
}
@@ -2123,7 +2124,8 @@ void cmSystemTools::FileTimeDelete(cmSystemToolsFileTime* t)
delete t;
}
bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t)
bool cmSystemTools::FileTimeGet(const std::string& fname,
cmSystemToolsFileTime* t)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemToolsWindowsHandle h = CreateFileW(
@@ -2138,7 +2140,7 @@ bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t)
}
#else
struct stat st;
if (stat(fname, &st) < 0) {
if (stat(fname.c_str(), &st) < 0) {
return false;
}
t->timeBuf.actime = st.st_atime;
@@ -2147,7 +2149,8 @@ bool cmSystemTools::FileTimeGet(const char* fname, cmSystemToolsFileTime* t)
return true;
}
bool cmSystemTools::FileTimeSet(const char* fname, cmSystemToolsFileTime* t)
bool cmSystemTools::FileTimeSet(const std::string& fname,
const cmSystemToolsFileTime* t)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemToolsWindowsHandle h = CreateFileW(
@@ -2159,7 +2162,7 @@ bool cmSystemTools::FileTimeSet(const char* fname, cmSystemToolsFileTime* t)
return SetFileTime(h, &t->timeCreation, &t->timeLastAccess,
&t->timeLastWrite) != 0;
#else
return utime(fname, &t->timeBuf) >= 0;
return utime(fname.c_str(), &t->timeBuf) >= 0;
#endif
}