This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, next has been updated via 0bb1daddaf0f450b8d040015c9135ad85fee9378 (commit) via 60c783676c91ff1ded2ed5e6fd50d0f9664032e5 (commit) via 158c6d1cffe863fde284d4e5eeeb8129d40ce0e9 (commit) from eb2eb7840ae2706aadeb9e8015656ed03843acd1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0bb1daddaf0f450b8d040015c9135ad85fee9378 commit 0bb1daddaf0f450b8d040015c9135ad85fee9378 Merge: eb2eb78 60c7836 Author: Brad King <brad.k...@kitware.com> AuthorDate: Mon Aug 4 10:16:41 2014 -0400 Commit: CMake Topic Stage <kwro...@kitware.com> CommitDate: Mon Aug 4 10:16:41 2014 -0400 Merge topic 'update-kwsys' into next 60c78367 Merge branch 'upstream-kwsys' into update-kwsys 158c6d1c KWSys 2014-08-04 (e787837a) http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=60c783676c91ff1ded2ed5e6fd50d0f9664032e5 commit 60c783676c91ff1ded2ed5e6fd50d0f9664032e5 Merge: ba60ff9 158c6d1 Author: Brad King <brad.k...@kitware.com> AuthorDate: Mon Aug 4 10:16:34 2014 -0400 Commit: Brad King <brad.k...@kitware.com> CommitDate: Mon Aug 4 10:16:34 2014 -0400 Merge branch 'upstream-kwsys' into update-kwsys http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=158c6d1cffe863fde284d4e5eeeb8129d40ce0e9 commit 158c6d1cffe863fde284d4e5eeeb8129d40ce0e9 Author: KWSys Robot <kwro...@kitware.com> AuthorDate: Mon Aug 4 08:59:12 2014 -0400 Commit: Brad King <brad.k...@kitware.com> CommitDate: Mon Aug 4 10:16:30 2014 -0400 KWSys 2014-08-04 (e787837a) Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ e787837a | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' 65b36ede..e787837a Ben Boeckel (4): 9927862c SystemTools: more string replacements b3d598b0 strings: remove unnecessary c_str calls ffe94132 SystemTools: use char instead of const char* f29fec7c Directory: accept strings in methods Rashad M (1): e787837a SharedForward: Cast away const to call execvp on MinGW 64-bit Change-Id: I96437b332971670cfcd953717c5563e9ba0f2b99 diff --git a/Directory.cxx b/Directory.cxx index b305fd7..741bcba 100644 --- a/Directory.cxx +++ b/Directory.cxx @@ -103,7 +103,7 @@ void Directory::Clear() namespace KWSYS_NAMESPACE { -bool Directory::Load(const char* name) +bool Directory::Load(const kwsys_stl::string& name) { this->Clear(); #if _MSC_VER < 1300 @@ -112,24 +112,24 @@ bool Directory::Load(const char* name) intptr_t srchHandle; #endif char* buf; - size_t n = strlen(name); - if ( name[n - 1] == '/' || name[n - 1] == '\\' ) + size_t n = name.size(); + if ( *name.rbegin() == '/' || *name.rbegin() == '\\' ) { buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name); + sprintf(buf, "%s*", name.c_str()); } else { // Make sure the slashes in the wildcard suffix are consistent with the // rest of the path buf = new char[n + 2 + 1]; - if ( strchr(name, '\\') ) + if ( name.find('\\') != name.npos ) { - sprintf(buf, "%s\\*", name); + sprintf(buf, "%s\\*", name.c_str()); } else { - sprintf(buf, "%s/*", name); + sprintf(buf, "%s/*", name.c_str()); } } struct _wfinddata_t data; // data of current file @@ -153,7 +153,7 @@ bool Directory::Load(const char* name) return _findclose(srchHandle) != -1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) +unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name) { #if _MSC_VER < 1300 long srchHandle; @@ -161,16 +161,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) intptr_t srchHandle; #endif char* buf; - size_t n = strlen(name); - if ( name[n - 1] == '/' ) + size_t n = name.size(); + if ( *name.rbegin() == '/' ) { buf = new char[n + 1 + 1]; - sprintf(buf, "%s*", name); + sprintf(buf, "%s*", name.c_str()); } else { buf = new char[n + 2 + 1]; - sprintf(buf, "%s/*", name); + sprintf(buf, "%s/*", name.c_str()); } struct _wfinddata_t data; // data of current file @@ -215,15 +215,11 @@ p=1992&sid=f16167f51964f1a68fe5041b8eb213b6 namespace KWSYS_NAMESPACE { -bool Directory::Load(const char* name) +bool Directory::Load(const kwsys_stl::string& name) { this->Clear(); - if (!name) - { - return 0; - } - DIR* dir = opendir(name); + DIR* dir = opendir(name.c_str()); if (!dir) { @@ -239,14 +235,9 @@ bool Directory::Load(const char* name) return 1; } -unsigned long Directory::GetNumberOfFilesInDirectory(const char* name) +unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name) { - DIR* dir = opendir(name); - - if (!dir) - { - return 0; - } + DIR* dir = opendir(name.c_str()); unsigned long count = 0; for (dirent* d = readdir(dir); d; d = readdir(dir) ) diff --git a/Directory.hxx.in b/Directory.hxx.in index 05217c4..0acb191 100644 --- a/Directory.hxx.in +++ b/Directory.hxx.in @@ -13,6 +13,13 @@ #define @KWSYS_NAMESPACE@_Directory_hxx #include <@KWSYS_NAMESPACE@/Configure.h> +#include <@KWSYS_NAMESPACE@/stl/string> + +/* Define these macros temporarily to keep the code readable. */ +#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS +# define kwsys_stl @KWSYS_NAMESPACE@_stl +# define kwsys_ios @KWSYS_NAMESPACE@_ios +#endif namespace @KWSYS_NAMESPACE@ { @@ -38,7 +45,7 @@ public: * in that directory. 0 is returned if the directory can not be * opened, 1 if it is opened. */ - bool Load(const char*); + bool Load(const kwsys_stl::string&); /** * Return the number of files in the current directory. @@ -49,7 +56,7 @@ public: * Return the number of files in the specified directory. * A higher performance static method. */ - static unsigned long GetNumberOfFilesInDirectory(const char*); + static unsigned long GetNumberOfFilesInDirectory(const kwsys_stl::string&); /** * Return the file at the given index, the indexing is 0 based @@ -77,4 +84,10 @@ private: } // namespace @KWSYS_NAMESPACE@ +/* Undefine temporary macros. */ +#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS +# undef kwsys_stl +# undef kwsys_ios +#endif + #endif diff --git a/Glob.cxx b/Glob.cxx index 8569b0e..0916d2e 100644 --- a/Glob.cxx +++ b/Glob.cxx @@ -218,7 +218,7 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, const kwsys_stl::string& dir) { kwsys::Directory d; - if ( !d.Load(dir.c_str()) ) + if ( !d.Load(dir) ) { return; } @@ -257,8 +257,8 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start, fullname = dir + "/" + fname; } - bool isDir = kwsys::SystemTools::FileIsDirectory(realname.c_str()); - bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname.c_str()); + bool isDir = kwsys::SystemTools::FileIsDirectory(realname); + bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname); if ( isDir && (!isSymLink || this->RecurseThroughSymlinks) ) { @@ -297,7 +297,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, } kwsys::Directory d; - if ( !d.Load(dir.c_str()) ) + if ( !d.Load(dir) ) { return; } @@ -342,12 +342,12 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start, //kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl; if ( !last && - !kwsys::SystemTools::FileIsDirectory(realname.c_str()) ) + !kwsys::SystemTools::FileIsDirectory(realname) ) { continue; } - if ( this->Internals->Expressions[start].find(fname.c_str()) ) + if ( this->Internals->Expressions[start].find(fname) ) { if ( last ) { @@ -371,7 +371,7 @@ bool Glob::FindFiles(const kwsys_stl::string& inexpr) this->Internals->Expressions.clear(); this->Internals->Files.clear(); - if ( !kwsys::SystemTools::FileIsFullPath(expr.c_str()) ) + if ( !kwsys::SystemTools::FileIsFullPath(expr) ) { expr = kwsys::SystemTools::GetCurrentWorkingDirectory(); expr += "/" + inexpr; diff --git a/SharedForward.h.in b/SharedForward.h.in index dd4d462..7ff29b4 100644 --- a/SharedForward.h.in +++ b/SharedForward.h.in @@ -512,7 +512,7 @@ static void kwsys_shared_forward_execvp(const char* cmd, /* Invoke the child process. */ #if defined(_MSC_VER) _execvp(cmd, argv); -#elif defined(__MINGW32__) +#elif defined(__MINGW32__) && !defined(__MINGW64__) execvp(cmd, argv); #else execvp(cmd, (char* const*)argv); diff --git a/SystemTools.cxx b/SystemTools.cxx index db94510..dcfd49c 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -206,12 +206,12 @@ static time_t windows_filetime_to_posix_time(const FILETIME& ft) #include <wctype.h> -inline int Mkdir(const char* dir) +inline int Mkdir(const kwsys_stl::string& dir) { return _wmkdir( KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); } -inline int Rmdir(const char* dir) +inline int Rmdir(const kwsys_stl::string& dir) { return _wrmdir( KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); @@ -232,15 +232,15 @@ inline const char* Getcwd(char* buf, unsigned int len) } return 0; } -inline int Chdir(const char* dir) +inline int Chdir(const kwsys_stl::string& dir) { #if defined(__BORLANDC__) - return chdir(dir); + return chdir(dir.c_str()); #else return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); #endif } -inline void Realpath(const char *path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) { kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); wchar_t *ptemp; @@ -260,28 +260,28 @@ inline void Realpath(const char *path, kwsys_stl::string & resolved_path) #include <sys/types.h> #include <fcntl.h> #include <unistd.h> -inline int Mkdir(const char* dir) +inline int Mkdir(const kwsys_stl::string& dir) { - return mkdir(dir, 00777); + return mkdir(dir.c_str(), 00777); } -inline int Rmdir(const char* dir) +inline int Rmdir(const kwsys_stl::string& dir) { - return rmdir(dir); + return rmdir(dir.c_str()); } inline const char* Getcwd(char* buf, unsigned int len) { return getcwd(buf, len); } -inline int Chdir(const char* dir) +inline int Chdir(const kwsys_stl::string& dir) { - return chdir(dir); + return chdir(dir.c_str()); } -inline void Realpath(const char *path, kwsys_stl::string & resolved_path) +inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) { char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH]; - char *ret = realpath(path, resolved_name); + char *ret = realpath(path.c_str(), resolved_name); if(ret) { resolved_path = ret; @@ -334,9 +334,9 @@ class SystemToolsTranslationMap : void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char* env) { #if defined(_WIN32) && !defined(__CYGWIN__) - const char* pathSep = ";"; + const char pathSep = ';'; #else - const char* pathSep = ":"; + const char pathSep = ':'; #endif if(!env) { @@ -351,7 +351,7 @@ void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char kwsys_stl::string pathEnv = cpathEnv; // A hack to make the below algorithm work. - if(!pathEnv.empty() && pathEnv[pathEnv.length()-1] != pathSep[0]) + if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep) { pathEnv += pathSep; } @@ -623,13 +623,13 @@ const char* SystemTools::GetExecutableExtension() #endif } -FILE* SystemTools::Fopen(const char* file, const char* mode) +FILE* SystemTools::Fopen(const kwsys_stl::string& file, const char* mode) { #ifdef _WIN32 return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), Encoding::ToWide(mode).c_str()); #else - return fopen(file, mode); + return fopen(file.c_str(), mode); #endif } @@ -639,15 +639,20 @@ bool SystemTools::MakeDirectory(const char* path) { return false; } + return SystemTools::MakeDirectory(kwsys_stl::string(path)); +} + +bool SystemTools::MakeDirectory(const kwsys_stl::string& path) +{ if(SystemTools::FileExists(path)) { return SystemTools::FileIsDirectory(path); } - kwsys_stl::string dir = path; - if(dir.empty()) + if(path.empty()) { return false; } + kwsys_stl::string dir = path; SystemTools::ConvertToUnixSlashes(dir); kwsys_stl::string::size_type pos = 0; @@ -655,11 +660,11 @@ bool SystemTools::MakeDirectory(const char* path) while((pos = dir.find('/', pos)) != kwsys_stl::string::npos) { topdir = dir.substr(0, pos); - Mkdir(topdir.c_str()); + Mkdir(topdir); pos++; } topdir = dir; - if(Mkdir(topdir.c_str()) != 0) + if(Mkdir(topdir) != 0) { // There is a bug in the Borland Run time library which makes MKDIR // return EACCES when it should return EEXISTS @@ -1021,7 +1026,7 @@ bool SystemTools::DeleteRegistryValue(const char *, KeyWOW64) } #endif -bool SystemTools::SameFile(const char* file1, const char* file2) +bool SystemTools::SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2) { #ifdef _WIN32 HANDLE hFile1, hFile2; @@ -1066,7 +1071,7 @@ bool SystemTools::SameFile(const char* file1, const char* file2) fiBuf1.nFileIndexLow == fiBuf2.nFileIndexLow); #else struct stat fileStat1, fileStat2; - if (stat(file1, &fileStat1) == 0 && stat(file2, &fileStat2) == 0) + if (stat(file1.c_str(), &fileStat1) == 0 && stat(file2.c_str(), &fileStat2) == 0) { // see if the files are the same file // check the device inode and size @@ -1085,24 +1090,34 @@ bool SystemTools::SameFile(const char* file1, const char* file2) //---------------------------------------------------------------------------- bool SystemTools::FileExists(const char* filename) { - if(!(filename && *filename)) + if(!filename) + { + return false; + } + return SystemTools::FileExists(kwsys_stl::string(filename)); +} + +//---------------------------------------------------------------------------- +bool SystemTools::FileExists(const kwsys_stl::string& filename) +{ + if(filename.empty()) { return false; } #if defined(__CYGWIN__) // Convert filename to native windows path if possible. char winpath[MAX_PATH]; - if(SystemTools::PathCygwinToWin32(filename, winpath)) + if(SystemTools::PathCygwinToWin32(filename.c_str(), winpath)) { return (GetFileAttributesA(winpath) != INVALID_FILE_ATTRIBUTES); } - return access(filename, R_OK) == 0; + return access(filename.c_str(), R_OK) == 0; #elif defined(_WIN32) return (GetFileAttributesW( SystemTools::ConvertToWindowsExtendedPath(filename).c_str()) != INVALID_FILE_ATTRIBUTES); #else - return access(filename, R_OK) == 0; + return access(filename.c_str(), R_OK) == 0; #endif } @@ -1119,6 +1134,18 @@ bool SystemTools::FileExists(const char* filename, bool isFile) } //---------------------------------------------------------------------------- +bool SystemTools::FileExists(const kwsys_stl::string& filename, bool isFile) +{ + if(SystemTools::FileExists(filename)) + { + // If isFile is set return not FileIsDirectory, + // so this will only be true if it is a file + return !isFile || !SystemTools::FileIsDirectory(filename); + } + return false; +} + +//---------------------------------------------------------------------------- #ifdef __CYGWIN__ bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path) { @@ -1142,7 +1169,7 @@ bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path) } #endif -bool SystemTools::Touch(const char* filename, bool create) +bool SystemTools::Touch(const kwsys_stl::string& filename, bool create) { if(create && !SystemTools::FileExists(filename)) { @@ -1174,13 +1201,13 @@ bool SystemTools::Touch(const char* filename, bool create) CloseHandle(h); #elif KWSYS_CXX_HAS_UTIMENSAT struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}}; - if(utimensat(AT_FDCWD, filename, times, 0) < 0) + if(utimensat(AT_FDCWD, filename.c_str(), times, 0) < 0) { return false; } #else struct stat st; - if(stat(filename, &st) < 0) + if(stat(filename.c_str(), &st) < 0) { return false; } @@ -1196,13 +1223,13 @@ bool SystemTools::Touch(const char* filename, bool create) # endif mtime }; - if(utimes(filename, times) < 0) + if(utimes(filename.c_str(), times) < 0) { return false; } # else struct utimbuf times = {st.st_atime, mtime.tv_sec}; - if(utime(filename, ×) < 0) + if(utime(filename.c_str(), ×) < 0) { return false; } @@ -1211,7 +1238,8 @@ bool SystemTools::Touch(const char* filename, bool create) return true; } -bool SystemTools::FileTimeCompare(const char* f1, const char* f2, +bool SystemTools::FileTimeCompare(const kwsys_stl::string& f1, + const kwsys_stl::string& f2, int* result) { // Default to same time. @@ -1219,12 +1247,12 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2, #if !defined(_WIN32) || defined(__CYGWIN__) // POSIX version. Use stat function to get file modification time. struct stat s1; - if(stat(f1, &s1) != 0) + if(stat(f1.c_str(), &s1) != 0) { return false; } struct stat s2; - if(stat(f2, &s2) != 0) + if(stat(f2.c_str(), &s2) != 0) { return false; } @@ -1535,6 +1563,17 @@ bool SystemTools::StringStartsWith(const char* str1, const char* str2) return len1 >= len2 && !strncmp(str1, str2, len2) ? true : false; } +// Returns if string starts with another string +bool SystemTools::StringStartsWith(const kwsys_stl::string& str1, const char* str2) +{ + if (!str2) + { + return false; + } + size_t len1 = str1.size(), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1.c_str(), str2, len2) ? true : false; +} + // Returns if string ends with another string bool SystemTools::StringEndsWith(const char* str1, const char* str2) { @@ -1546,6 +1585,17 @@ bool SystemTools::StringEndsWith(const char* str1, const char* str2) return len1 >= len2 && !strncmp(str1 + (len1 - len2), str2, len2) ? true : false; } +// Returns if string ends with another string +bool SystemTools::StringEndsWith(const kwsys_stl::string& str1, const char* str2) +{ + if (!str2) + { + return false; + } + size_t len1 = str1.size(), len2 = strlen(str2); + return len1 >= len2 && !strncmp(str1.c_str() + (len1 - len2), str2, len2) ? true : false; +} + // Returns a pointer to the last occurence of str2 in str1 const char* SystemTools::FindLastString(const char* str1, const char* str2) { @@ -1615,7 +1665,7 @@ kwsys_stl::string SystemTools::CropString(const kwsys_stl::string& s, } //---------------------------------------------------------------------------- -kwsys_stl::vector<kwsys::String> SystemTools::SplitString(const char* p, char sep, bool isPath) +kwsys_stl::vector<kwsys::String> SystemTools::SplitString(const kwsys_stl::string& p, char sep, bool isPath) { kwsys_stl::string path = p; kwsys_stl::vector<kwsys::String> paths; @@ -1917,7 +1967,7 @@ SystemTools::ConvertToWindowsExtendedPath(const kwsys_stl::string &source) #endif // change // to /, and escape any spaces in the path -kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const kwsys_stl::string& path) { kwsys_stl::string ret = path; @@ -1947,7 +1997,7 @@ kwsys_stl::string SystemTools::ConvertToUnixOutputPath(const char* path) return ret; } -kwsys_stl::string SystemTools::ConvertToOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToOutputPath(const kwsys_stl::string& path) { #if defined(_WIN32) && !defined(__CYGWIN__) return SystemTools::ConvertToWindowsOutputPath(path); @@ -1957,13 +2007,12 @@ kwsys_stl::string SystemTools::ConvertToOutputPath(const char* path) } // remove double slashes not at the start -kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const char* path) +kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const kwsys_stl::string& path) { kwsys_stl::string ret; // make it big enough for all of path and double quotes - ret.reserve(strlen(path)+3); + ret.reserve(path.size()+3); // put path into the string - ret.assign(path); ret = path; kwsys_stl::string::size_type pos = 0; // first convert all of the slashes @@ -2005,8 +2054,8 @@ kwsys_stl::string SystemTools::ConvertToWindowsOutputPath(const char* path) return ret; } -bool SystemTools::CopyFileIfDifferent(const char* source, - const char* destination) +bool SystemTools::CopyFileIfDifferent(const kwsys_stl::string& source, + const kwsys_stl::string& destination) { // special check for a destination that is a directory // FilesDiffer does not handle file to directory compare @@ -2017,7 +2066,7 @@ bool SystemTools::CopyFileIfDifferent(const char* source, new_destination += '/'; kwsys_stl::string source_name = source; new_destination += SystemTools::GetFilenameName(source_name); - if(SystemTools::FilesDiffer(source, new_destination.c_str())) + if(SystemTools::FilesDiffer(source, new_destination)) { return SystemTools::CopyFileAlways(source, destination); } @@ -2040,8 +2089,8 @@ bool SystemTools::CopyFileIfDifferent(const char* source, #define KWSYS_ST_BUFFER 4096 -bool SystemTools::FilesDiffer(const char* source, - const char* destination) +bool SystemTools::FilesDiffer(const kwsys_stl::string& source, + const kwsys_stl::string& destination) { #if defined(_WIN32) @@ -2079,13 +2128,13 @@ bool SystemTools::FilesDiffer(const char* source, #else struct stat statSource; - if (stat(source, &statSource) != 0) + if (stat(source.c_str(), &statSource) != 0) { return true; } struct stat statDestination; - if (stat(destination, &statDestination) != 0) + if (stat(destination.c_str(), &statDestination) != 0) { return true; } @@ -2103,15 +2152,15 @@ bool SystemTools::FilesDiffer(const char* source, #endif #if defined(_WIN32) - kwsys::ifstream finSource(source, + kwsys::ifstream finSource(source.c_str(), (kwsys_ios::ios::binary | kwsys_ios::ios::in)); - kwsys::ifstream finDestination(destination, + kwsys::ifstream finDestination(destination.c_str(), (kwsys_ios::ios::binary | kwsys_ios::ios::in)); #else - kwsys::ifstream finSource(source); - kwsys::ifstream finDestination(destination); + kwsys::ifstream finSource(source.c_str()); + kwsys::ifstream finDestination(destination.c_str()); #endif if(!finSource || !finDestination) { @@ -2156,7 +2205,7 @@ bool SystemTools::FilesDiffer(const char* source, /** * Copy a file named by "source" to the file named by "destination". */ -bool SystemTools::CopyFileAlways(const char* source, const char* destination) +bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination) { // If files are the same do not copy if ( SystemTools::SameFile(source, destination) ) @@ -2172,31 +2221,33 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) // If destination is a directory, try to create a file with the same // name as the source in that directory. - kwsys_stl::string new_destination; + kwsys_stl::string real_destination = destination; + kwsys_stl::string destination_dir; if(SystemTools::FileExists(destination) && SystemTools::FileIsDirectory(destination)) { - new_destination = destination; - SystemTools::ConvertToUnixSlashes(new_destination); - new_destination += '/'; + destination_dir = real_destination; + SystemTools::ConvertToUnixSlashes(real_destination); + real_destination += '/'; kwsys_stl::string source_name = source; - new_destination += SystemTools::GetFilenameName(source_name); - destination = new_destination.c_str(); + real_destination += SystemTools::GetFilenameName(source_name); + } + else + { + destination_dir = SystemTools::GetFilenamePath(destination); } // Create destination directory - kwsys_stl::string destination_dir = destination; - destination_dir = SystemTools::GetFilenamePath(destination_dir); - SystemTools::MakeDirectory(destination_dir.c_str()); + SystemTools::MakeDirectory(destination_dir); // Open files #if defined(_WIN32) || defined(__CYGWIN__) - kwsys::ifstream fin(source, + kwsys::ifstream fin(source.c_str(), kwsys_ios::ios::binary | kwsys_ios::ios::in); #else - kwsys::ifstream fin(source); + kwsys::ifstream fin(source.c_str()); #endif if(!fin) { @@ -2207,13 +2258,13 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) // can be written to. // If the remove fails continue so that files in read only directories // that do not allow file removal can be modified. - SystemTools::RemoveFile(destination); + SystemTools::RemoveFile(real_destination); #if defined(_WIN32) || defined(__CYGWIN__) - kwsys::ofstream fout(destination, + kwsys::ofstream fout(real_destination.c_str(), kwsys_ios::ios::binary | kwsys_ios::ios::out | kwsys_ios::ios::trunc); #else - kwsys::ofstream fout(destination, + kwsys::ofstream fout(real_destination.c_str(), kwsys_ios::ios::out | kwsys_ios::ios::trunc); #endif if(!fout) @@ -2249,7 +2300,7 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) } if ( perms ) { - if ( !SystemTools::SetPermissions(destination, perm) ) + if ( !SystemTools::SetPermissions(real_destination, perm) ) { return false; } @@ -2258,7 +2309,7 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) } //---------------------------------------------------------------------------- -bool SystemTools::CopyAFile(const char* source, const char* destination, +bool SystemTools::CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always) { if(always) @@ -2275,13 +2326,13 @@ bool SystemTools::CopyAFile(const char* source, const char* destination, * Copy a directory content from "source" directory to the directory named by * "destination". */ -bool SystemTools::CopyADirectory(const char* source, const char* destination, +bool SystemTools::CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always) { Directory dir; #ifdef _WIN32 dir.Load(Encoding::ToNarrow( - SystemTools::ConvertToWindowsExtendedPath(source)).c_str()); + SystemTools::ConvertToWindowsExtendedPath(source))); #else dir.Load(source); #endif @@ -2298,13 +2349,13 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination, kwsys_stl::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if(SystemTools::FileIsDirectory(fullPath.c_str())) + if(SystemTools::FileIsDirectory(fullPath)) { kwsys_stl::string fullDestPath = destination; fullDestPath += "/"; fullDestPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if (!SystemTools::CopyADirectory(fullPath.c_str(), - fullDestPath.c_str(), + if (!SystemTools::CopyADirectory(fullPath, + fullDestPath, always)) { return false; @@ -2312,7 +2363,7 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination, } else { - if(!SystemTools::CopyAFile(fullPath.c_str(), destination, always)) + if(!SystemTools::CopyAFile(fullPath, destination, always)) { return false; } @@ -2365,7 +2416,7 @@ int SystemTools::Strucmp(const char *s1, const char *s2) } // return file's modified time -long int SystemTools::ModifiedTime(const char* filename) +long int SystemTools::ModifiedTime(const kwsys_stl::string& filename) { long int mt = 0; #ifdef _WIN32 @@ -2379,7 +2430,7 @@ long int SystemTools::ModifiedTime(const char* filename) } #else struct stat fs; - if (stat(filename, &fs) == 0) + if (stat(filename.c_str(), &fs) == 0) { mt = static_cast<long int>(fs.st_mtime); } @@ -2388,7 +2439,7 @@ long int SystemTools::ModifiedTime(const char* filename) } // return file's creation time -long int SystemTools::CreationTime(const char* filename) +long int SystemTools::CreationTime(const kwsys_stl::string& filename) { long int ct = 0; #ifdef _WIN32 @@ -2402,7 +2453,7 @@ long int SystemTools::CreationTime(const char* filename) } #else struct stat fs; - if (stat(filename, &fs) == 0) + if (stat(filename.c_str(), &fs) == 0) { ct = fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0; } @@ -2518,7 +2569,7 @@ kwsys_stl::string SystemTools::GetLastSystemError() return strerror(e); } -bool SystemTools::RemoveFile(const char* source) +bool SystemTools::RemoveFile(const kwsys_stl::string& source) { #ifdef _WIN32 mode_t mode; @@ -2533,7 +2584,7 @@ bool SystemTools::RemoveFile(const char* source) bool res = _wunlink(SystemTools::ConvertToWindowsExtendedPath(source).c_str()) == 0; #else - bool res = unlink(source) != 0 ? false : true; + bool res = unlink(source.c_str()) != 0 ? false : true; #endif #ifdef _WIN32 if ( !res ) @@ -2544,7 +2595,7 @@ bool SystemTools::RemoveFile(const char* source) return res; } -bool SystemTools::RemoveADirectory(const char* source) +bool SystemTools::RemoveADirectory(const kwsys_stl::string& source) { // Add write permission to the directory so we can modify its // content to remove files and directories from it. @@ -2562,7 +2613,7 @@ bool SystemTools::RemoveADirectory(const char* source) Directory dir; #ifdef _WIN32 dir.Load(Encoding::ToNarrow( - SystemTools::ConvertToWindowsExtendedPath(source)).c_str()); + SystemTools::ConvertToWindowsExtendedPath(source))); #else dir.Load(source); #endif @@ -2575,17 +2626,17 @@ bool SystemTools::RemoveADirectory(const char* source) kwsys_stl::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast<unsigned long>(fileNum)); - if(SystemTools::FileIsDirectory(fullPath.c_str()) && - !SystemTools::FileIsSymlink(fullPath.c_str())) + if(SystemTools::FileIsDirectory(fullPath) && + !SystemTools::FileIsSymlink(fullPath)) { - if (!SystemTools::RemoveADirectory(fullPath.c_str())) + if (!SystemTools::RemoveADirectory(fullPath)) { return false; } } else { - if(!SystemTools::RemoveFile(fullPath.c_str())) + if(!SystemTools::RemoveFile(fullPath)) { return false; } @@ -2647,7 +2698,7 @@ kwsys_stl::string SystemTools { tryPath = *p; tryPath += name; - if(SystemTools::FileExists(tryPath.c_str())) + if(SystemTools::FileExists(tryPath)) { return tryPath; } @@ -2667,7 +2718,7 @@ kwsys_stl::string SystemTools bool no_system_path) { kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path); - if(tryPath != "" && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(!tryPath.empty() && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2686,7 +2737,7 @@ kwsys_stl::string SystemTools bool no_system_path) { kwsys_stl::string tryPath = SystemTools::FindName(name, userPaths, no_system_path); - if(tryPath != "" && SystemTools::FileIsDirectory(tryPath.c_str())) + if(!tryPath.empty() && SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2708,7 +2759,14 @@ kwsys_stl::string SystemTools::FindProgram( { return ""; } - kwsys_stl::string name = nameIn; + return SystemTools::FindProgram(kwsys_stl::string(nameIn), userPaths, no_system_path); +} + +kwsys_stl::string SystemTools::FindProgram( + const kwsys_stl::string& name, + const kwsys_stl::vector<kwsys_stl::string>& userPaths, + bool no_system_path) +{ kwsys_stl::vector<kwsys_stl::string> extensions; #if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) bool hasExtension = false; @@ -2733,16 +2791,16 @@ kwsys_stl::string SystemTools::FindProgram( { tryPath = name; tryPath += *i; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } // now try just the name tryPath = name; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2788,8 +2846,8 @@ kwsys_stl::string SystemTools::FindProgram( tryPath = *p; tryPath += name; tryPath += *ext; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2797,8 +2855,8 @@ kwsys_stl::string SystemTools::FindProgram( // now try it without them tryPath = *p; tryPath += name; - if(SystemTools::FileExists(tryPath.c_str()) && - !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) && + !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2816,7 +2874,7 @@ kwsys_stl::string SystemTools::FindProgram( it != names.end() ; ++it) { // Try to find the program. - kwsys_stl::string result = SystemTools::FindProgram(it->c_str(), + kwsys_stl::string result = SystemTools::FindProgram(*it, path, noSystemPath); if ( !result.empty() ) @@ -2833,7 +2891,7 @@ kwsys_stl::string SystemTools::FindProgram( * found. Otherwise, the empty string is returned. */ kwsys_stl::string SystemTools -::FindLibrary(const char* name, +::FindLibrary(const kwsys_stl::string& name, const kwsys_stl::vector<kwsys_stl::string>& userPaths) { // See if the executable exists as written. @@ -2874,8 +2932,8 @@ kwsys_stl::string SystemTools tryPath = *p; tryPath += name; tryPath += ".framework"; - if(SystemTools::FileExists(tryPath.c_str()) - && SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2884,8 +2942,8 @@ kwsys_stl::string SystemTools tryPath = *p; tryPath += name; tryPath += ".lib"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2894,8 +2952,8 @@ kwsys_stl::string SystemTools tryPath += "lib"; tryPath += name; tryPath += ".so"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2903,8 +2961,8 @@ kwsys_stl::string SystemTools tryPath += "lib"; tryPath += name; tryPath += ".a"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2912,8 +2970,8 @@ kwsys_stl::string SystemTools tryPath += "lib"; tryPath += name; tryPath += ".sl"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2921,8 +2979,8 @@ kwsys_stl::string SystemTools tryPath += "lib"; tryPath += name; tryPath += ".dylib"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2930,8 +2988,8 @@ kwsys_stl::string SystemTools tryPath += "lib"; tryPath += name; tryPath += ".dll"; - if(SystemTools::FileExists(tryPath.c_str()) - && !SystemTools::FileIsDirectory(tryPath.c_str())) + if(SystemTools::FileExists(tryPath) + && !SystemTools::FileIsDirectory(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } @@ -2942,32 +3000,33 @@ kwsys_stl::string SystemTools return ""; } -kwsys_stl::string SystemTools::GetRealPath(const char* path) +kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path) { kwsys_stl::string ret; Realpath(path, ret); return ret; } -bool SystemTools::FileIsDirectory(const char* name) +bool SystemTools::FileIsDirectory(const kwsys_stl::string& inName) { - if (!*name) + if (inName.empty()) { return false; } - size_t length = strlen(name); + size_t length = inName.size(); + const char* name = inName.c_str(); // Remove any trailing slash from the name except in a root component. char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; std::string string_buffer; size_t last = length-1; if(last > 0 && (name[last] == '/' || name[last] == '\\') - && strcmp(name, "/") !=0 && name[last-1] != ':') + && strcmp(name, "/") != 0 && name[last-1] != ':') { - if(last < sizeof(local_buffer)) + if (last < sizeof(local_buffer)) { memcpy(local_buffer, name, last); - local_buffer[last] = 0; + local_buffer[last] = '\0'; name = local_buffer; } else @@ -2997,14 +3056,14 @@ bool SystemTools::FileIsDirectory(const char* name) } } -bool SystemTools::FileIsSymlink(const char* name) +bool SystemTools::FileIsSymlink(const kwsys_stl::string& name) { #if defined( _WIN32 ) (void)name; return false; #else struct stat fs; - if(lstat(name, &fs) == 0) + if(lstat(name.c_str(), &fs) == 0) { return S_ISLNK(fs.st_mode); } @@ -3053,7 +3112,7 @@ bool SystemTools::ReadSymlink(const char* newName, } #endif -int SystemTools::ChangeDirectory(const char *dir) +int SystemTools::ChangeDirectory(const kwsys_stl::string& dir) { return Chdir(dir); } @@ -3090,7 +3149,7 @@ bool SystemTools::SplitProgramPath(const char* in_name, file = ""; SystemTools::ConvertToUnixSlashes(dir); - if(!SystemTools::FileIsDirectory(dir.c_str())) + if(!SystemTools::FileIsDirectory(dir)) { kwsys_stl::string::size_type slashPos = dir.rfind("/"); if(slashPos != kwsys_stl::string::npos) @@ -3104,7 +3163,7 @@ bool SystemTools::SplitProgramPath(const char* in_name, dir = ""; } } - if(!(dir == "") && !SystemTools::FileIsDirectory(dir.c_str())) + if(!(dir.empty()) && !SystemTools::FileIsDirectory(dir)) { kwsys_stl::string oldDir = in_name; SystemTools::ConvertToUnixSlashes(oldDir); @@ -3125,8 +3184,8 @@ bool SystemTools::FindProgramPath(const char* argv0, kwsys_stl::string self = argv0 ? argv0 : ""; failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); - self = SystemTools::FindProgram(self.c_str()); - if(!SystemTools::FileExists(self.c_str())) + self = SystemTools::FindProgram(self); + if(!SystemTools::FileExists(self)) { if(buildDir) { @@ -3144,7 +3203,7 @@ bool SystemTools::FindProgramPath(const char* argv0, } if(installPrefix) { - if(!SystemTools::FileExists(self.c_str())) + if(!SystemTools::FileExists(self)) { failures.push_back(self); self = installPrefix; @@ -3152,7 +3211,7 @@ bool SystemTools::FindProgramPath(const char* argv0, self += exeName; } } - if(!SystemTools::FileExists(self.c_str())) + if(!SystemTools::FileExists(self)) { failures.push_back(self); kwsys_ios::ostringstream msg; @@ -3193,12 +3252,12 @@ void SystemTools::AddTranslationPath(const kwsys_stl::string& a, const kwsys_stl SystemTools::ConvertToUnixSlashes(path_b); // First check this is a directory path, since we don't want the table to // grow too fat - if( SystemTools::FileIsDirectory( path_a.c_str() ) ) + if( SystemTools::FileIsDirectory( path_a ) ) { // Make sure the path is a full path and does not contain no '..' // Ken--the following code is incorrect. .. can be in a valid path // for example /home/martink/MyHubba...Hubba/Src - if( SystemTools::FileIsFullPath(path_b.c_str()) && path_b.find("..") + if( SystemTools::FileIsFullPath(path_b) && path_b.find("..") == kwsys_stl::string::npos ) { // Before inserting make sure path ends with '/' @@ -3355,7 +3414,7 @@ kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path } // compute the relative path from here to there -kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remote) +kwsys_stl::string SystemTools::RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote) { if(!SystemTools::FileIsFullPath(local)) { @@ -3745,7 +3804,7 @@ bool SystemTools::ComparePath(const kwsys_stl::string& c1, const kwsys_stl::stri } //---------------------------------------------------------------------------- -bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator) +bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator) { kwsys_stl::string data(str); kwsys_stl::string::size_type lpos = 0; @@ -3769,7 +3828,7 @@ bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& l } //---------------------------------------------------------------------------- -bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines) +bool SystemTools::Split(const kwsys_stl::string& str, kwsys_stl::vector<kwsys_stl::string>& lines) { kwsys_stl::string data(str); kwsys_stl::string::size_type lpos = 0; @@ -4062,7 +4121,7 @@ bool SystemTools::LocateFileInDir(const char *filename, } temp += filename_base; - if (SystemTools::FileExists(temp.c_str())) + if (SystemTools::FileExists(temp)) { res = true; filename_found = temp; @@ -4111,9 +4170,18 @@ bool SystemTools::LocateFileInDir(const char *filename, return res; } +bool SystemTools::FileIsFullPath(const kwsys_stl::string& in_name) +{ + return SystemTools::FileIsFullPath(in_name.c_str(), in_name.size()); +} + bool SystemTools::FileIsFullPath(const char* in_name) { - size_t len = strlen(in_name); + return SystemTools::FileIsFullPath(in_name, in_name[0] ? (in_name[1] ? 2 : 1) : 0); +} + +bool SystemTools::FileIsFullPath(const char* in_name, size_t len) +{ #if defined(_WIN32) || defined(__CYGWIN__) // On Windows, the name must be at least two characters long. if(len < 2) @@ -4222,7 +4290,7 @@ void SystemTools::SplitProgramFromArgs(const char* path, { kwsys_stl::string tryProg = dir.substr(0, spacePos); // See if the file exists - if(SystemTools::FileExists(tryProg.c_str())) + if(SystemTools::FileExists(tryProg)) { program = tryProg; // remove trailing spaces from program @@ -4236,7 +4304,7 @@ void SystemTools::SplitProgramFromArgs(const char* path, return; } // Now try and find the program in the path - findProg = SystemTools::FindProgram(tryProg.c_str(), e); + findProg = SystemTools::FindProgram(tryProg, e); if(!findProg.empty()) { program = findProg; @@ -4408,7 +4476,11 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) { return false; } + return SystemTools::GetPermissions(kwsys_stl::string(file), mode); +} +bool SystemTools::GetPermissions(const kwsys_stl::string& file, mode_t& mode) +{ #if defined(_WIN32) DWORD attr = GetFileAttributesW( SystemTools::ConvertToWindowsExtendedPath(file).c_str()); @@ -4433,7 +4505,8 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) { mode |= S_IFREG; } - const char* ext = strrchr(file, '.'); + size_t dotPos = file.rfind('.'); + const char* ext = dotPos == file.npos ? 0 : (file.c_str() + dotPos); if(ext && (Strucmp(ext, ".exe") == 0 || Strucmp(ext, ".com") == 0 || Strucmp(ext, ".cmd") == 0 || @@ -4443,7 +4516,7 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode) } #else struct stat st; - if ( stat(file, &st) < 0 ) + if ( stat(file.c_str(), &st) < 0 ) { return false; } @@ -4458,6 +4531,11 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) { return false; } + return SystemTools::SetPermissions(kwsys_stl::string(file), mode); +} + +bool SystemTools::SetPermissions(const kwsys_stl::string& file, mode_t mode) +{ if ( !SystemTools::FileExists(file) ) { return false; @@ -4466,7 +4544,7 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) if ( _wchmod(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), mode) < 0 ) #else - if ( chmod(file, mode) < 0 ) + if ( chmod(file.c_str(), mode) < 0 ) #endif { return false; @@ -4475,7 +4553,7 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) return true; } -kwsys_stl::string SystemTools::GetParentDirectory(const char* fileOrDir) +kwsys_stl::string SystemTools::GetParentDirectory(const kwsys_stl::string& fileOrDir) { return SystemTools::GetFilenamePath(fileOrDir); } diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index b7c7206..2514699 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -158,7 +158,9 @@ public: * Returns true if str1 starts (respectively ends) with str2 */ static bool StringStartsWith(const char* str1, const char* str2); + static bool StringStartsWith(const kwsys_stl::string& str1, const char* str2); static bool StringEndsWith(const char* str1, const char* str2); + static bool StringEndsWith(const kwsys_stl::string& str1, const char* str2); /** * Returns a pointer to the last occurence of str2 in str1 @@ -183,7 +185,7 @@ public: s starts with a / then the first element of the returned array will be /, so /foo/bar will be [/, foo, bar] */ - static kwsys_stl::vector<String> SplitString(const char* s, char separator = '/', + static kwsys_stl::vector<String> SplitString(const kwsys_stl::string& s, char separator = '/', bool isPath = false); /** * Perform a case-independent string comparison @@ -201,8 +203,8 @@ public: * Split a string on its newlines into multiple lines * Return false only if the last line stored had no newline */ - static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l); - static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l, char separator); + static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l); + static bool Split(const kwsys_stl::string& s, kwsys_stl::vector<kwsys_stl::string>& l, char separator); /** * Return string with space added between capitalized words @@ -265,13 +267,13 @@ public: * For windows this calls ConvertToWindowsOutputPath and for unix * it calls ConvertToUnixOutputPath */ - static kwsys_stl::string ConvertToOutputPath(const char*); + static kwsys_stl::string ConvertToOutputPath(const kwsys_stl::string&); /** * Convert the path to a string that can be used in a unix makefile. * double slashes are removed, and spaces are escaped. */ - static kwsys_stl::string ConvertToUnixOutputPath(const char*); + static kwsys_stl::string ConvertToUnixOutputPath(const kwsys_stl::string&); /** * Convert the path to string that can be used in a windows project or @@ -279,7 +281,7 @@ public: * the string, the slashes are converted to windows style backslashes, and * if there are spaces in the string it is double quoted. */ - static kwsys_stl::string ConvertToWindowsOutputPath(const char*); + static kwsys_stl::string ConvertToWindowsOutputPath(const kwsys_stl::string&); /** * Return true if a file exists in the current directory. @@ -288,7 +290,9 @@ public: * if it is a file or a directory. */ static bool FileExists(const char* filename, bool isFile); + static bool FileExists(const kwsys_stl::string& filename, bool isFile); static bool FileExists(const char* filename); + static bool FileExists(const kwsys_stl::string& filename); /** * Converts Cygwin path to Win32 path. Uses dictionary container for @@ -307,7 +311,7 @@ public: /** Change the modification time or create a file */ - static bool Touch(const char* filename, bool create); + static bool Touch(const kwsys_stl::string& filename, bool create); /** * Compare file modification times. @@ -315,7 +319,8 @@ public: * When true is returned, result has -1, 0, +1 for * f1 older, same, or newer than f2. */ - static bool FileTimeCompare(const char* f1, const char* f2, + static bool FileTimeCompare(const kwsys_stl::string& f1, + const kwsys_stl::string& f2, int* result); /** @@ -377,7 +382,7 @@ public: * the event of an error (non-existent path, permissions issue, * etc.) the original path is returned. */ - static kwsys_stl::string GetRealPath(const char* path); + static kwsys_stl::string GetRealPath(const kwsys_stl::string& path); /** * Split a path name into its root component and the rest of the @@ -470,6 +475,7 @@ public: /** * Return whether the path represents a full path (not relative) */ + static bool FileIsFullPath(const kwsys_stl::string&); static bool FileIsFullPath(const char*); /** @@ -493,7 +499,7 @@ public: /** * Get the parent directory of the directory or file */ - static kwsys_stl::string GetParentDirectory(const char* fileOrDir); + static kwsys_stl::string GetParentDirectory(const kwsys_stl::string& fileOrDir); /** * Check if the given file or directory is in subdirectory of dir @@ -508,7 +514,7 @@ public: /** * Open a file considering unicode. */ - static FILE* Fopen(const char* file, const char* mode); + static FILE* Fopen(const kwsys_stl::string& file, const char* mode); /** * Make a new directory if it is not there. This function @@ -516,35 +522,36 @@ public: * prior to calling this function. */ static bool MakeDirectory(const char* path); + static bool MakeDirectory(const kwsys_stl::string& path); /** * Copy the source file to the destination file only * if the two files differ. */ - static bool CopyFileIfDifferent(const char* source, - const char* destination); + static bool CopyFileIfDifferent(const kwsys_stl::string& source, + const kwsys_stl::string& destination); /** * Compare the contents of two files. Return true if different */ - static bool FilesDiffer(const char* source, const char* destination); + static bool FilesDiffer(const kwsys_stl::string& source, const kwsys_stl::string& destination); /** * Return true if the two files are the same file */ - static bool SameFile(const char* file1, const char* file2); + static bool SameFile(const kwsys_stl::string& file1, const kwsys_stl::string& file2); /** * Copy a file. */ - static bool CopyFileAlways(const char* source, const char* destination); + static bool CopyFileAlways(const kwsys_stl::string& source, const kwsys_stl::string& destination); /** * Copy a file. If the "always" argument is true the file is always * copied. If it is false, the file is copied only if it is new or * has changed. */ - static bool CopyAFile(const char* source, const char* destination, + static bool CopyAFile(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always = true); /** @@ -553,18 +560,18 @@ public: * always copied. If it is false, only files that have changed or * are new are copied. */ - static bool CopyADirectory(const char* source, const char* destination, + static bool CopyADirectory(const kwsys_stl::string& source, const kwsys_stl::string& destination, bool always = true); /** * Remove a file */ - static bool RemoveFile(const char* source); + static bool RemoveFile(const kwsys_stl::string& source); /** * Remove a directory */ - static bool RemoveADirectory(const char* source); + static bool RemoveADirectory(const kwsys_stl::string& source); /** * Get the maximum full file path length @@ -594,12 +601,17 @@ public: */ static kwsys_stl::string FindProgram( const char* name, - const kwsys_stl::vector<kwsys_stl::string>& path = + const kwsys_stl::vector<kwsys_stl::string>& path = + kwsys_stl::vector<kwsys_stl::string>(), + bool no_system_path = false); + static kwsys_stl::string FindProgram( + const kwsys_stl::string& name, + const kwsys_stl::vector<kwsys_stl::string>& path = kwsys_stl::vector<kwsys_stl::string>(), bool no_system_path = false); static kwsys_stl::string FindProgram( const kwsys_stl::vector<kwsys_stl::string>& names, - const kwsys_stl::vector<kwsys_stl::string>& path = + const kwsys_stl::vector<kwsys_stl::string>& path = kwsys_stl::vector<kwsys_stl::string>(), bool no_system_path = false); @@ -607,18 +619,18 @@ public: * Find a library in the system PATH, with optional extra paths */ static kwsys_stl::string FindLibrary( - const char* name, + const kwsys_stl::string& name, const kwsys_stl::vector<kwsys_stl::string>& path); /** * Return true if the file is a directory */ - static bool FileIsDirectory(const char* name); + static bool FileIsDirectory(const kwsys_stl::string& name); /** * Return true if the file is a symlink */ - static bool FileIsSymlink(const char* name); + static bool FileIsSymlink(const kwsys_stl::string& name); /** * Return true if the file has a given signature (first set of bytes) @@ -686,17 +698,17 @@ public: /a/b/c/d to /a/b/c1/d1 -> ../../c1/d1 from /usr/src to /usr/src/test/blah/foo.cpp -> test/blah/foo.cpp */ - static kwsys_stl::string RelativePath(const char* local, const char* remote); + static kwsys_stl::string RelativePath(const kwsys_stl::string& local, const kwsys_stl::string& remote); /** * Return file's modified time */ - static long int ModifiedTime(const char* filename); + static long int ModifiedTime(const kwsys_stl::string& filename); /** * Return file's creation time (Win32: works only for NTFS, not FAT) */ - static long int CreationTime(const char* filename); + static long int CreationTime(const kwsys_stl::string& filename); #if defined( _MSC_VER ) typedef unsigned short mode_t; @@ -706,7 +718,9 @@ public: * Get and set permissions of the file. */ static bool GetPermissions(const char* file, mode_t& mode); + static bool GetPermissions(const kwsys_stl::string& file, mode_t& mode); static bool SetPermissions(const char* file, mode_t mode); + static bool SetPermissions(const kwsys_stl::string& file, mode_t mode); /** ----------------------------------------------------------------- * Time Manipulation Routines @@ -793,7 +807,7 @@ public: /** * Change directory to the directory specified */ - static int ChangeDirectory(const char* dir); + static int ChangeDirectory(const kwsys_stl::string& dir); /** * Get the result of strerror(errno) @@ -901,6 +915,11 @@ private: } /** + * Actual implementation of FileIsFullPath. + */ + static bool FileIsFullPath(const char*, size_t); + + /** * Find a filename (file or directory) in the system PATH, with * optional extra paths. */ diff --git a/testSystemTools.cxx b/testSystemTools.cxx index 8b21081..15123eb 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -132,7 +132,7 @@ static bool CheckFileOperations() res = false; } - if (!kwsys::SystemTools::MakeDirectory(testNewDir.c_str())) + if (!kwsys::SystemTools::MakeDirectory(testNewDir)) { kwsys_ios::cerr << "Problem with MakeDirectory for: " @@ -148,7 +148,7 @@ static bool CheckFileOperations() res = false; } - if (!kwsys::SystemTools::RemoveFile(testNewFile.c_str())) + if (!kwsys::SystemTools::RemoveFile(testNewFile)) { kwsys_ios::cerr << "Problem with RemoveFile: " @@ -157,7 +157,7 @@ static bool CheckFileOperations() } kwsys::SystemTools::Touch(testNewFile.c_str(), true); - if (!kwsys::SystemTools::RemoveADirectory(testNewDir.c_str())) + if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) { kwsys_ios::cerr << "Problem with RemoveADirectory for: " @@ -183,7 +183,7 @@ static bool CheckFileOperations() "012345678901234567890123456789012345678901234567890123456789" "0123456789.txt"); - if (!kwsys::SystemTools::MakeDirectory(testNewLongDir.c_str())) + if (!kwsys::SystemTools::MakeDirectory(testNewLongDir)) { kwsys_ios::cerr << "Problem with MakeDirectory for: " @@ -199,7 +199,7 @@ static bool CheckFileOperations() res = false; } - if (!kwsys::SystemTools::RemoveFile(testNewLongFile.c_str())) + if (!kwsys::SystemTools::RemoveFile(testNewLongFile)) { kwsys_ios::cerr << "Problem with RemoveFile: " @@ -208,7 +208,7 @@ static bool CheckFileOperations() } kwsys::SystemTools::Touch(testNewLongFile.c_str(), true); - if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir.c_str())) + if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir)) { kwsys_ios::cerr << "Problem with RemoveADirectory for: " ----------------------------------------------------------------------- Summary of changes: Source/kwsys/Directory.cxx | 41 ++--- Source/kwsys/Directory.hxx.in | 17 +- Source/kwsys/Glob.cxx | 14 +- Source/kwsys/SharedForward.h.in | 2 +- Source/kwsys/SystemTools.cxx | 368 +++++++++++++++++++++++--------------- Source/kwsys/SystemTools.hxx.in | 77 +++++--- Source/kwsys/testSystemTools.cxx | 12 +- 7 files changed, 316 insertions(+), 215 deletions(-) hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org http://public.kitware.com/mailman/listinfo/cmake-commits