summaryrefslogtreecommitdiffstats
path: root/Source/kwsys
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/CMakeLists.txt7
-rw-r--r--Source/kwsys/CPU.h.in4
-rw-r--r--Source/kwsys/Directory.cxx46
-rw-r--r--Source/kwsys/Directory.hxx.in17
-rw-r--r--Source/kwsys/Glob.cxx14
-rw-r--r--Source/kwsys/ProcessUNIX.c2
-rw-r--r--Source/kwsys/ProcessWin32.c17
-rw-r--r--Source/kwsys/SharedForward.h.in2
-rw-r--r--Source/kwsys/SystemInformation.cxx17
-rw-r--r--Source/kwsys/SystemTools.cxx701
-rw-r--r--Source/kwsys/SystemTools.hxx.in99
-rw-r--r--Source/kwsys/Terminal.c6
-rw-r--r--Source/kwsys/kwsysPlatformTests.cmake8
-rw-r--r--Source/kwsys/testCommandLineArguments1.cxx2
-rw-r--r--Source/kwsys/testDynamicLoader.cxx2
-rw-r--r--Source/kwsys/testProcess.c17
-rw-r--r--Source/kwsys/testSystemTools.cxx322
-rw-r--r--Source/kwsys/testSystemTools.h.in5
18 files changed, 871 insertions, 417 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index 5e6a226..8ca4360 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -1171,10 +1171,9 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS})
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE})
TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE})
- SET(TEST_SYSTEMTOOLS_BIN_FILE
- "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.bin")
- SET(TEST_SYSTEMTOOLS_SRC_FILE
- "${CMAKE_CURRENT_SOURCE_DIR}/testSystemTools.cxx")
+
+ SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/testSystemTools.h.in
${PROJECT_BINARY_DIR}/testSystemTools.h)
diff --git a/Source/kwsys/CPU.h.in b/Source/kwsys/CPU.h.in
index 2e1a584..626914b 100644
--- a/Source/kwsys/CPU.h.in
+++ b/Source/kwsys/CPU.h.in
@@ -80,6 +80,10 @@
#elif defined(__mips) || defined(__mips__) || defined(__MIPS__)
# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+/* OpenRISC 1000 */
+#elif defined(__or1k__)
+# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
+
/* RS/6000 */
#elif defined(__THW_RS600) || defined(_IBMR2) || defined(_POWER)
# define @KWSYS_NAMESPACE@_CPU_ENDIAN_ID @KWSYS_NAMESPACE@_CPU_ENDIAN_ID_BIG
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index d54e607..741bcba 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/kwsys/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,16 +112,25 @@ bool Directory::Load(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() == '/' || *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];
- sprintf(buf, "%s/*", name);
+ if ( name.find('\\') != name.npos )
+ {
+ sprintf(buf, "%s\\*", name.c_str());
+ }
+ else
+ {
+ sprintf(buf, "%s/*", name.c_str());
+ }
}
struct _wfinddata_t data; // data of current file
@@ -144,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;
@@ -152,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
@@ -206,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)
{
@@ -230,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/Source/kwsys/Directory.hxx.in b/Source/kwsys/Directory.hxx.in
index 05217c4..0acb191 100644
--- a/Source/kwsys/Directory.hxx.in
+++ b/Source/kwsys/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/Source/kwsys/Glob.cxx b/Source/kwsys/Glob.cxx
index 8569b0e..0916d2e 100644
--- a/Source/kwsys/Glob.cxx
+++ b/Source/kwsys/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/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c
index 241e295..ca9d424 100644
--- a/Source/kwsys/ProcessUNIX.c
+++ b/Source/kwsys/ProcessUNIX.c
@@ -68,6 +68,7 @@ do.
#include <signal.h> /* sigaction */
#include <dirent.h> /* DIR, dirent */
#include <ctype.h> /* isspace */
+#include <assert.h> /* assert */
#if defined(__VMS)
# define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK
@@ -450,6 +451,7 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command)
}
for(i=0; i < n; ++i)
{
+ assert(command[i]); /* Quiet Clang scan-build. */
newCommands[cp->NumberOfCommands][i] = strdup(command[i]);
if(!newCommands[cp->NumberOfCommands][i])
{
diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c
index c8ec754..ef71f26 100644
--- a/Source/kwsys/ProcessWin32.c
+++ b/Source/kwsys/ProcessWin32.c
@@ -36,6 +36,9 @@ a UNIX-style select system call.
#pragma warning (push, 1)
#endif
#include <windows.h> /* Windows API */
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+#endif
#include <string.h> /* strlen, strdup */
#include <stdio.h> /* sprintf */
#include <io.h> /* _unlink */
@@ -335,7 +338,14 @@ kwsysProcess* kwsysProcess_New(void)
windows. */
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
GetVersionEx(&osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
/* Win9x no longer supported. */
@@ -2370,7 +2380,14 @@ static kwsysProcess_List* kwsysProcess_List_New(void)
/* Select an implementation. */
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
GetVersionEx(&osv);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
self->NT4 = (osv.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osv.dwMajorVersion < 5)? 1:0;
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
index dd4d462..7ff29b4 100644
--- a/Source/kwsys/SharedForward.h.in
+++ b/Source/kwsys/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/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 6544098..84b5f39 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -60,6 +60,9 @@
#if defined(_WIN32)
# include <windows.h>
+# if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# endif
# include <errno.h>
# if defined(KWSYS_SYS_HAS_PSAPI)
# include <psapi.h>
@@ -3696,7 +3699,10 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
// install ours
struct sigaction sa;
sa.sa_sigaction=(SigAction)StacktraceSignalHandler;
- sa.sa_flags=SA_SIGINFO|SA_RESTART|SA_RESETHAND;
+ sa.sa_flags=SA_SIGINFO|SA_RESETHAND;
+# ifdef SA_RESTART
+ sa.sa_flags|=SA_RESTART;
+# endif
sigemptyset(&sa.sa_mask);
sigaction(SIGABRT,&sa,0);
@@ -3783,7 +3789,7 @@ bool SystemInformationImplementation::QueryLinuxMemory()
return false;
}
- if( unameInfo.release!=0 && strlen(unameInfo.release)>=3 )
+ if( strlen(unameInfo.release)>=3 )
{
// release looks like "2.6.3-15mdk-i686-up-4GB"
char majorChar=unameInfo.release[0];
@@ -5060,6 +5066,10 @@ bool SystemInformationImplementation::QueryOSInformation()
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
ZeroMemory (&osvi, sizeof (OSVERSIONINFOEXW));
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
bOsVersionInfoEx = GetVersionExW ((OSVERSIONINFOW*)&osvi);
if (!bOsVersionInfoEx)
{
@@ -5069,6 +5079,9 @@ bool SystemInformationImplementation::QueryOSInformation()
return false;
}
}
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
switch (osvi.dwPlatformId)
{
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 704cbbc..b1221e3 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -82,6 +82,9 @@
# ifndef INVALID_FILE_ATTRIBUTES
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
# endif
+# if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# endif
#elif defined (__CYGWIN__)
# include <windows.h>
# undef _WIN32
@@ -187,17 +190,34 @@ static inline char *realpath(const char *path, char *resolved_path)
}
#endif
+#ifdef _WIN32
+static time_t windows_filetime_to_posix_time(const FILETIME& ft)
+{
+ LARGE_INTEGER date;
+ date.HighPart = ft.dwHighDateTime;
+ date.LowPart = ft.dwLowDateTime;
+
+ // removes the diff between 1970 and 1601
+ date.QuadPart -= ((LONGLONG)(369 * 365 + 89) * 24 * 3600 * 10000000);
+
+ // converts back from 100-nanoseconds to seconds
+ return date.QuadPart / 10000000;
+}
+#endif
+
#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__))
#include <wctype.h>
-inline int Mkdir(const char* dir)
+inline int Mkdir(const kwsys_stl::string& dir)
{
- return _wmkdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
+ 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::Encoding::ToWide(dir).c_str());
+ return _wrmdir(
+ KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str());
}
inline const char* Getcwd(char* buf, unsigned int len)
{
@@ -215,15 +235,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;
@@ -243,28 +263,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;
@@ -317,9 +337,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)
{
@@ -334,7 +354,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;
}
@@ -606,13 +626,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(Encoding::ToWide(file).c_str(),
+ return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(),
Encoding::ToWide(mode).c_str());
#else
- return fopen(file, mode);
+ return fopen(file.c_str(), mode);
#endif
}
@@ -622,15 +642,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;
@@ -638,11 +663,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
@@ -1004,7 +1029,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;
@@ -1049,7 +1074,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
@@ -1068,23 +1093,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(Encoding::ToWide(filename).c_str())
+ 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
}
@@ -1101,6 +1137,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)
{
@@ -1124,7 +1172,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))
{
@@ -1137,10 +1185,11 @@ bool SystemTools::Touch(const char* filename, bool create)
return false;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
- HANDLE h = CreateFileW(Encoding::ToWide(filename).c_str(),
- FILE_WRITE_ATTRIBUTES,
- FILE_SHARE_WRITE, 0, OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS, 0);
+ HANDLE h = CreateFileW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_WRITE, 0, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, 0);
if(!h)
{
return false;
@@ -1155,13 +1204,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;
}
@@ -1177,13 +1226,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, &times) < 0)
+ if(utime(filename.c_str(), &times) < 0)
{
return false;
}
@@ -1192,7 +1241,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.
@@ -1200,12 +1250,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;
}
@@ -1242,13 +1292,15 @@ bool SystemTools::FileTimeCompare(const char* f1, const char* f2,
// Windows version. Get the modification time from extended file attributes.
WIN32_FILE_ATTRIBUTE_DATA f1d;
WIN32_FILE_ATTRIBUTE_DATA f2d;
- if(!GetFileAttributesExW(Encoding::ToWide(f1).c_str(),
- GetFileExInfoStandard, &f1d))
+ if(!GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(f1).c_str(),
+ GetFileExInfoStandard, &f1d))
{
return false;
}
- if(!GetFileAttributesExW(Encoding::ToWide(f2).c_str(),
- GetFileExInfoStandard, &f2d))
+ if(!GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(f2).c_str(),
+ GetFileExInfoStandard, &f2d))
{
return false;
}
@@ -1514,6 +1566,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)
{
@@ -1525,6 +1588,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)
{
@@ -1594,7 +1668,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;
@@ -1830,8 +1904,73 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
}
}
+#ifdef _WIN32
+// Convert local paths to UNC style paths
+kwsys_stl::wstring
+SystemTools::ConvertToWindowsExtendedPath(const kwsys_stl::string &source)
+{
+ kwsys_stl::wstring wsource = Encoding::ToWide(source);
+
+ // Resolve any relative paths
+ DWORD wfull_len;
+
+ /* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
+ * won't return a large enough buffer size if the input is too small */
+ wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
+ kwsys_stl::vector<wchar_t> wfull(wfull_len);
+ GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
+
+ /* This should get the correct size without any extra padding from the
+ * previous size workaround. */
+ wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
+
+ if(wfull_len >= 2 && isalpha(wfull[0]) && wfull[1] == L':')
+ { /* C:\Foo\bar\FooBar.txt */
+ return L"\\\\?\\" + kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 2 && wfull[0] == L'\\' && wfull[1] == L'\\')
+ { /* Starts with \\ */
+ if(wfull_len >= 4 && wfull[2] == L'?' && wfull[3] == L'\\')
+ { /* Starts with \\?\ */
+ if(wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
+ wfull[6] == L'C' && wfull[7] == L'\\')
+ { /* \\?\UNC\Foo\bar\FooBar.txt */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':')
+ { /* \\?\C:\Foo\bar\FooBar.txt */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ else if(wfull_len >= 5)
+ { /* \\?\Foo\bar\FooBar.txt */
+ return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[4]);
+ }
+ }
+ else if(wfull_len >= 4 && wfull[2] == L'.' && wfull[3] == L'\\')
+ { /* Starts with \\.\ a device name */
+ if(wfull_len >= 6 && isalpha(wfull[4]) && wfull[5] == L':')
+ { /* \\.\C:\Foo\bar\FooBar.txt */
+ return L"\\\\?\\" + kwsys_stl::wstring(&wfull[4]);
+ }
+ else if(wfull_len >= 5)
+ { /* \\.\Foo\bar\ Device name is left unchanged */
+ return kwsys_stl::wstring(&wfull[0]);
+ }
+ }
+ else if(wfull_len >= 3)
+ { /* \\Foo\bar\FooBar.txt */
+ return L"\\\\?\\UNC\\" + kwsys_stl::wstring(&wfull[2]);
+ }
+ }
+
+ // If this case has been reached, then the path is invalid. Leave it
+ // unchanged
+ return Encoding::ToWide(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;
@@ -1861,7 +2000,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);
@@ -1871,13 +2010,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
@@ -1919,8 +2057,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
@@ -1931,7 +2069,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);
}
@@ -1954,23 +2092,25 @@ 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)
WIN32_FILE_ATTRIBUTE_DATA statSource;
- if (GetFileAttributesExW(Encoding::ToWide(source).c_str(),
- GetFileExInfoStandard,
- &statSource) == 0)
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(source).c_str(),
+ GetFileExInfoStandard,
+ &statSource) == 0)
{
return true;
}
WIN32_FILE_ATTRIBUTE_DATA statDestination;
- if (GetFileAttributesExW(Encoding::ToWide(destination).c_str(),
- GetFileExInfoStandard,
- &statDestination) == 0)
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(destination).c_str(),
+ GetFileExInfoStandard,
+ &statDestination) == 0)
{
return true;
}
@@ -1991,13 +2131,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;
}
@@ -2015,15 +2155,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)
{
@@ -2068,7 +2208,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) )
@@ -2084,31 +2224,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)
{
@@ -2119,13 +2261,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)
@@ -2161,7 +2303,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;
}
@@ -2170,7 +2312,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)
@@ -2187,11 +2329,16 @@ 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)));
+#else
dir.Load(source);
+#endif
size_t fileNum;
if ( !SystemTools::MakeDirectory(destination) )
{
@@ -2205,13 +2352,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;
@@ -2219,7 +2366,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;
}
@@ -2234,15 +2381,28 @@ bool SystemTools::CopyADirectory(const char* source, const char* destination,
// return size of file; also returns zero if no file exists
unsigned long SystemTools::FileLength(const char* filename)
{
- struct stat fs;
- if (stat(filename, &fs) != 0)
+ unsigned long length = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard, &fs) != 0)
{
- return 0;
+ /* To support the full 64-bit file size, use fs.nFileSizeHigh
+ * and fs.nFileSizeLow to construct the 64 bit size
+
+ length = ((__int64)fs.nFileSizeHigh << 32) + fs.nFileSizeLow;
+ */
+ length = static_cast<unsigned long>(fs.nFileSizeLow);
}
- else
+#else
+ struct stat fs;
+ if (stat(filename, &fs) == 0)
{
- return static_cast<unsigned long>(fs.st_size);
+ length = static_cast<unsigned long>(fs.st_size);
}
+#endif
+ return length;
}
int SystemTools::Strucmp(const char *s1, const char *s2)
@@ -2259,31 +2419,49 @@ 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)
{
- struct stat fs;
- if (stat(filename, &fs) != 0)
+ long int mt = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard,
+ &fs) != 0)
{
- return 0;
+ mt = windows_filetime_to_posix_time(fs.ftLastWriteTime);
}
- else
+#else
+ struct stat fs;
+ if (stat(filename.c_str(), &fs) == 0)
{
- return static_cast<long int>(fs.st_mtime);
+ mt = static_cast<long int>(fs.st_mtime);
}
+#endif
+ return mt;
}
// return file's creation time
-long int SystemTools::CreationTime(const char* filename)
+long int SystemTools::CreationTime(const kwsys_stl::string& filename)
{
- struct stat fs;
- if (stat(filename, &fs) != 0)
+ long int ct = 0;
+#ifdef _WIN32
+ WIN32_FILE_ATTRIBUTE_DATA fs;
+ if (GetFileAttributesExW(
+ SystemTools::ConvertToWindowsExtendedPath(filename).c_str(),
+ GetFileExInfoStandard,
+ &fs) != 0)
{
- return 0;
+ ct = windows_filetime_to_posix_time(fs.ftCreationTime);
}
- else
+#else
+ struct stat fs;
+ if (stat(filename.c_str(), &fs) == 0)
{
- return fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0;
+ ct = fs.st_ctime >= 0 ? static_cast<long int>(fs.st_ctime) : 0;
}
+#endif
+ return ct;
}
bool SystemTools::ConvertDateMacroString(const char *str, time_t *tmt)
@@ -2394,7 +2572,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;
@@ -2406,9 +2584,10 @@ bool SystemTools::RemoveFile(const char* source)
SystemTools::SetPermissions(source, S_IWRITE);
#endif
#ifdef _WIN32
- bool res = _wunlink(Encoding::ToWide(source).c_str()) != 0 ? false : true;
+ 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 )
@@ -2419,7 +2598,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.
@@ -2435,7 +2614,12 @@ bool SystemTools::RemoveADirectory(const char* source)
}
Directory dir;
+#ifdef _WIN32
+ dir.Load(Encoding::ToNarrow(
+ SystemTools::ConvertToWindowsExtendedPath(source)));
+#else
dir.Load(source);
+#endif
size_t fileNum;
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
{
@@ -2445,17 +2629,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;
}
@@ -2517,7 +2701,7 @@ kwsys_stl::string SystemTools
{
tryPath = *p;
tryPath += name;
- if(SystemTools::FileExists(tryPath.c_str()))
+ if(SystemTools::FileExists(tryPath))
{
return tryPath;
}
@@ -2537,7 +2721,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);
}
@@ -2556,7 +2740,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);
}
@@ -2578,7 +2762,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;
@@ -2603,16 +2794,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);
}
@@ -2658,8 +2849,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);
}
@@ -2667,8 +2858,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);
}
@@ -2686,7 +2877,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() )
@@ -2703,7 +2894,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.
@@ -2744,8 +2935,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);
}
@@ -2754,8 +2945,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);
}
@@ -2764,8 +2955,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);
}
@@ -2773,8 +2964,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);
}
@@ -2782,8 +2973,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);
}
@@ -2791,8 +2982,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);
}
@@ -2800,8 +2991,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);
}
@@ -2812,32 +3003,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
@@ -2849,7 +3041,8 @@ bool SystemTools::FileIsDirectory(const char* name)
// Now check the file node type.
#if defined( _WIN32 )
- DWORD attr = GetFileAttributesW(Encoding::ToWide(name).c_str());
+ DWORD attr = GetFileAttributesW(
+ SystemTools::ConvertToWindowsExtendedPath(name).c_str());
if (attr != INVALID_FILE_ATTRIBUTES)
{
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
@@ -2866,14 +3059,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);
}
@@ -2922,7 +3115,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);
}
@@ -2959,7 +3152,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)
@@ -2973,7 +3166,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);
@@ -2994,8 +3187,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)
{
@@ -3013,7 +3206,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;
@@ -3021,7 +3214,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;
@@ -3062,12 +3255,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 '/'
@@ -3224,7 +3417,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))
{
@@ -3235,9 +3428,12 @@ kwsys_stl::string SystemTools::RelativePath(const char* local, const char* remot
return "";
}
+ kwsys_stl::string l = SystemTools::CollapseFullPath(local);
+ kwsys_stl::string r = SystemTools::CollapseFullPath(remote);
+
// split up both paths into arrays of strings using / as a separator
- kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(local, '/', true);
- kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(remote, '/', true);
+ kwsys_stl::vector<kwsys::String> localSplit = SystemTools::SplitString(l, '/', true);
+ kwsys_stl::vector<kwsys::String> remoteSplit = SystemTools::SplitString(r, '/', true);
kwsys_stl::vector<kwsys::String> commonPath; // store shared parts of path in this array
kwsys_stl::vector<kwsys::String> finalPath; // store the final relative path here
// count up how many matching directory names there are from the start
@@ -3343,6 +3539,16 @@ static int GetCasePathName(const kwsys_stl::string & pathIn,
kwsys_stl::string test_str = casePath;
test_str += path_components[idx];
+ // If path component contains wildcards, we skip matching
+ // because these filenames are not allowed on windows,
+ // and we do not want to match a different file.
+ if(path_components[idx].find('*') != kwsys_stl::string::npos ||
+ path_components[idx].find('?') != kwsys_stl::string::npos)
+ {
+ casePath = "";
+ return 0;
+ }
+
WIN32_FIND_DATAW findData;
HANDLE hFind = ::FindFirstFileW(Encoding::ToWide(test_str).c_str(),
&findData);
@@ -3614,7 +3820,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;
@@ -3638,7 +3844,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;
@@ -3931,7 +4137,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;
@@ -3980,9 +4186,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)
@@ -4041,7 +4256,7 @@ bool SystemTools::GetShortPath(const kwsys_stl::string& path, kwsys_stl::string&
kwsys_stl::wstring wtempPath = Encoding::ToWide(tempPath);
kwsys_stl::vector<wchar_t> buffer(wtempPath.size()+1);
buffer[0] = 0;
- ret = GetShortPathNameW(Encoding::ToWide(tempPath).c_str(),
+ ret = GetShortPathNameW(wtempPath.c_str(),
&buffer[0], static_cast<DWORD>(wtempPath.size()));
if(buffer[0] == 0 || ret > wtempPath.size())
@@ -4091,7 +4306,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
@@ -4105,7 +4320,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;
@@ -4277,9 +4492,14 @@ 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(Encoding::ToWide(file).c_str());
+ DWORD attr = GetFileAttributesW(
+ SystemTools::ConvertToWindowsExtendedPath(file).c_str());
if(attr == INVALID_FILE_ATTRIBUTES)
{
return false;
@@ -4301,7 +4521,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 ||
@@ -4311,7 +4532,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;
}
@@ -4326,14 +4547,20 @@ 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;
}
#ifdef _WIN32
- if ( _wchmod(Encoding::ToWide(file).c_str(), mode) < 0 )
+ 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;
@@ -4342,7 +4569,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);
}
@@ -4389,111 +4616,6 @@ void SystemTools::Delay(unsigned int msec)
#endif
}
-void SystemTools::ConvertWindowsCommandLineToUnixArguments(
- const char *cmd_line, int *argc, char ***argv)
-{
- if (!cmd_line || !argc || !argv)
- {
- return;
- }
-
- // A space delimites an argument except when it is inside a quote
-
- (*argc) = 1;
-
- size_t cmd_line_len = strlen(cmd_line);
-
- size_t i;
- for (i = 0; i < cmd_line_len; i++)
- {
- while (isspace(cmd_line[i]) && i < cmd_line_len)
- {
- i++;
- }
- if (i < cmd_line_len)
- {
- if (cmd_line[i] == '\"')
- {
- i++;
- while (cmd_line[i] != '\"' && i < cmd_line_len)
- {
- i++;
- }
- (*argc)++;
- }
- else
- {
- while (!isspace(cmd_line[i]) && i < cmd_line_len)
- {
- i++;
- }
- (*argc)++;
- }
- }
- }
-
- (*argv) = new char* [(*argc) + 1];
- (*argv)[(*argc)] = NULL;
-
- // Set the first arg to be the exec name
-
- (*argv)[0] = new char [1024];
-#ifdef _WIN32
- wchar_t tmp[1024];
- ::GetModuleFileNameW(0, tmp, 1024);
- strcpy((*argv)[0], Encoding::ToNarrow(tmp).c_str());
-#else
- (*argv)[0][0] = '\0';
-#endif
-
- // Allocate the others
-
- int j;
- for (j = 1; j < (*argc); j++)
- {
- (*argv)[j] = new char [cmd_line_len + 10];
- }
-
- // Grab the args
-
- size_t pos;
- int argc_idx = 1;
-
- for (i = 0; i < cmd_line_len; i++)
- {
- while (isspace(cmd_line[i]) && i < cmd_line_len)
- {
- i++;
- }
- if (i < cmd_line_len)
- {
- if (cmd_line[i] == '\"')
- {
- i++;
- pos = i;
- while (cmd_line[i] != '\"' && i < cmd_line_len)
- {
- i++;
- }
- memcpy((*argv)[argc_idx], &cmd_line[pos], i - pos);
- (*argv)[argc_idx][i - pos] = '\0';
- argc_idx++;
- }
- else
- {
- pos = i;
- while (!isspace(cmd_line[i]) && i < cmd_line_len)
- {
- i++;
- }
- memcpy((*argv)[argc_idx], &cmd_line[pos], i - pos);
- (*argv)[argc_idx][i - pos] = '\0';
- argc_idx++;
- }
- }
- }
- }
-
kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion()
{
kwsys_stl::string res;
@@ -4510,6 +4632,10 @@ kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion()
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (push)
+# pragma warning (disable:4996)
+#endif
bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi);
if (!bOsVersionInfoEx)
{
@@ -4519,6 +4645,9 @@ kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion()
return 0;
}
}
+#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning (pop)
+#endif
switch (osvi.dwPlatformId)
{
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index fb55848..e88bc8f 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/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
@@ -249,18 +251,29 @@ public:
* Replace Windows file system slashes with Unix-style slashes.
*/
static void ConvertToUnixSlashes(kwsys_stl::string& path);
-
+
+#ifdef _WIN32
+ /**
+ * Convert the path to an extended length path to avoid MAX_PATH length
+ * limitations on Windows. If the input is a local path the result will be
+ * prefixed with \\?\; if the input is instead a network path, the result
+ * will be prefixed with \\?\UNC\. All output will also be converted to
+ * absolute paths with Windows-style backslashes.
+ **/
+ static kwsys_stl::wstring ConvertToWindowsExtendedPath(const kwsys_stl::string&);
+#endif
+
/**
* 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
@@ -268,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.
@@ -277,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
@@ -296,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.
@@ -304,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);
/**
@@ -366,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
@@ -459,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*);
/**
@@ -482,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
@@ -497,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
@@ -505,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);
/**
@@ -542,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
@@ -583,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);
@@ -596,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)
@@ -675,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;
@@ -695,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
@@ -782,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)
@@ -831,15 +856,6 @@ public:
*/
static kwsys_stl::string GetOperatingSystemNameAndVersion();
- /**
- * Convert windows-style arguments given as a command-line string
- * into more traditional argc/argv arguments.
- * Note that argv[0] will be assigned the executable name using
- * the GetModuleFileName() function.
- */
- static void ConvertWindowsCommandLineToUnixArguments(
- const char *cmd_line, int *argc, char ***argv);
-
/** -----------------------------------------------------------------
* URL Manipulation Routines
* -----------------------------------------------------------------
@@ -890,6 +906,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/Source/kwsys/Terminal.c b/Source/kwsys/Terminal.c
index 6d7ec41..e13003f 100644
--- a/Source/kwsys/Terminal.c
+++ b/Source/kwsys/Terminal.c
@@ -104,11 +104,11 @@ void kwsysTerminal_cfprintf(int color, FILE* stream, const char* format, ...)
}
/*--------------------------------------------------------------------------*/
-/* Detect cases when a stream is definately not interactive. */
+/* Detect cases when a stream is definitely not interactive. */
#if !defined(KWSYS_TERMINAL_ISATTY_WORKS)
static int kwsysTerminalStreamIsNotInteractive(FILE* stream)
{
- /* The given stream is definately not interactive if it is a regular
+ /* The given stream is definitely not interactive if it is a regular
file. */
struct stat stream_stat;
if(fstat(fileno(stream), &stream_stat) == 0)
@@ -212,7 +212,7 @@ static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
(void)default_tty;
return isatty(fileno(stream))? 1:0;
#else
- /* Check for cases in which the stream is definately not a tty. */
+ /* Check for cases in which the stream is definitely not a tty. */
if(kwsysTerminalStreamIsNotInteractive(stream))
{
return 0;
diff --git a/Source/kwsys/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake
index f9ee254..16bc969 100644
--- a/Source/kwsys/kwsysPlatformTests.cmake
+++ b/Source/kwsys/kwsysPlatformTests.cmake
@@ -13,7 +13,7 @@ SET(KWSYS_PLATFORM_TEST_FILE_C kwsysPlatformTestsC.c)
SET(KWSYS_PLATFORM_TEST_FILE_CXX kwsysPlatformTestsCXX.cxx)
MACRO(KWSYS_PLATFORM_TEST lang var description invert)
- IF("${var}_COMPILED" MATCHES "^${var}_COMPILED$")
+ IF(NOT DEFINED ${var}_COMPILED)
MESSAGE(STATUS "${description}")
TRY_COMPILE(${var}_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
@@ -43,7 +43,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert)
MESSAGE(STATUS "${description} - no")
ENDIF(${var}_COMPILED)
ENDIF(${invert} MATCHES INVERT)
- ENDIF("${var}_COMPILED" MATCHES "^${var}_COMPILED$")
+ ENDIF()
IF(${invert} MATCHES INVERT)
IF(${var}_COMPILED)
SET(${var} 0)
@@ -60,7 +60,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert)
ENDMACRO(KWSYS_PLATFORM_TEST)
MACRO(KWSYS_PLATFORM_TEST_RUN lang var description invert)
- IF("${var}" MATCHES "^${var}$")
+ IF(NOT DEFINED ${var})
MESSAGE(STATUS "${description}")
TRY_RUN(${var} ${var}_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
@@ -107,7 +107,7 @@ MACRO(KWSYS_PLATFORM_TEST_RUN lang var description invert)
MESSAGE(STATUS "${description} - failed to compile")
ENDIF(${var}_COMPILED)
ENDIF(${invert} MATCHES INVERT)
- ENDIF("${var}" MATCHES "^${var}$")
+ ENDIF()
IF(${invert} MATCHES INVERT)
IF(${var}_COMPILED)
diff --git a/Source/kwsys/testCommandLineArguments1.cxx b/Source/kwsys/testCommandLineArguments1.cxx
index 3b84c38..b65c37f 100644
--- a/Source/kwsys/testCommandLineArguments1.cxx
+++ b/Source/kwsys/testCommandLineArguments1.cxx
@@ -21,6 +21,7 @@
# include "kwsys_ios_iostream.h.in"
#endif
+#include <assert.h> /* assert */
#include <string.h> /* strcmp */
int testCommandLineArguments1(int argc, char* argv[])
@@ -83,6 +84,7 @@ int testCommandLineArguments1(int argc, char* argv[])
}
for ( cc = 0; cc < newArgc; ++ cc )
{
+ assert(newArgv[cc]); /* Quiet Clang scan-build. */
kwsys_ios::cout << "Unused argument[" << cc << "] = [" << newArgv[cc] << "]"
<< kwsys_ios::endl;
if ( cc >= 9 )
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index 1bff707..58adb84 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -108,7 +108,7 @@ int testDynamicLoader(int argc, char *argv[])
// Make sure that inexistent lib is giving correct result
res += TestDynamicLoader("azerty_", "foo_bar",0,0,0);
// Make sure that random binary file cannot be assimilated as dylib
- res += TestDynamicLoader(TEST_SYSTEMTOOLS_BIN_FILE, "wp",0,0,0);
+ res += TestDynamicLoader(TEST_SYSTEMTOOLS_SOURCE_DIR "/testSystemTools.bin", "wp",0,0,0);
#endif
#ifdef __linux__
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c
index 6d5eb71..47c3fb0 100644
--- a/Source/kwsys/testProcess.c
+++ b/Source/kwsys/testProcess.c
@@ -11,13 +11,16 @@
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(Process.h)
+#include KWSYS_HEADER(Encoding.h)
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
# include "Process.h.in"
+# include "Encoding.h.in"
#endif
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -102,6 +105,7 @@ static int test4(int argc, const char* argv[])
fprintf(stderr, "Output before crash on stderr from crash test.\n");
fflush(stdout);
fflush(stderr);
+ assert(invalidAddress); /* Quiet Clang scan-build. */
/* Provoke deliberate crash by writing to the invalid address. */
*invalidAddress = 0;
fprintf(stdout, "Output after crash on stdout from crash test.\n");
@@ -393,6 +397,19 @@ int runChild(const char* cmd[], int state, int exception, int value,
int main(int argc, const char* argv[])
{
int n = 0;
+
+#ifdef _WIN32
+ int i;
+ char new_args[10][_MAX_PATH];
+ LPWSTR* w_av = CommandLineToArgvW(GetCommandLineW(), &argc);
+ for(i=0; i<argc; i++)
+ {
+ kwsysEncoding_wcstombs(new_args[i], w_av[i], _MAX_PATH);
+ argv[i] = new_args[i];
+ }
+ LocalFree(w_av);
+#endif
+
#if 0
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 69825a8..b41532b 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -98,32 +98,124 @@ static bool CheckEscapeChars(kwsys_stl::string input,
static bool CheckFileOperations()
{
bool res = true;
-
- if (kwsys::SystemTools::DetectFileType(TEST_SYSTEMTOOLS_BIN_FILE) !=
+ const kwsys_stl::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
+ "/testSystemTools.bin");
+ const kwsys_stl::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
+ "/testSystemTools.cxx");
+ const kwsys_stl::string testNewDir(TEST_SYSTEMTOOLS_BINARY_DIR
+ "/testSystemToolsNewDir");
+ const kwsys_stl::string testNewFile(testNewDir + "/testNewFile.txt");
+
+ if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
kwsys::SystemTools::FileTypeBinary)
{
kwsys_ios::cerr
<< "Problem with DetectFileType - failed to detect type of: "
- << TEST_SYSTEMTOOLS_BIN_FILE << kwsys_ios::endl;
+ << testBinFile << kwsys_ios::endl;
res = false;
}
- if (kwsys::SystemTools::DetectFileType(TEST_SYSTEMTOOLS_SRC_FILE) !=
+ if (kwsys::SystemTools::DetectFileType(testTxtFile.c_str()) !=
kwsys::SystemTools::FileTypeText)
{
kwsys_ios::cerr
<< "Problem with DetectFileType - failed to detect type of: "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << testTxtFile << kwsys_ios::endl;
res = false;
}
-
- if (kwsys::SystemTools::FileLength(TEST_SYSTEMTOOLS_BIN_FILE) != 766)
+
+ if (kwsys::SystemTools::FileLength(testBinFile.c_str()) != 766)
{
kwsys_ios::cerr
<< "Problem with FileLength - incorrect length for: "
- << TEST_SYSTEMTOOLS_BIN_FILE << kwsys_ios::endl;
- res = false;
+ << testBinFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::MakeDirectory(testNewDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with MakeDirectory for: "
+ << testNewDir << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true))
+ {
+ kwsys_ios::cerr
+ << "Problem with Touch for: "
+ << testNewFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::RemoveFile(testNewFile))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveFile: "
+ << testNewFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ kwsys::SystemTools::Touch(testNewFile.c_str(), true);
+ if (!kwsys::SystemTools::RemoveADirectory(testNewDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveADirectory for: "
+ << testNewDir << kwsys_ios::endl;
+ res = false;
+ }
+
+#ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
+ // Perform the same file and directory creation and deletion tests but
+ // with paths > 256 characters in length.
+
+ const kwsys_stl::string testNewLongDir(
+ TEST_SYSTEMTOOLS_BINARY_DIR "/"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "01234567890123");
+ const kwsys_stl::string testNewLongFile(testNewLongDir + "/"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "0123456789.txt");
+
+ if (!kwsys::SystemTools::MakeDirectory(testNewLongDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with MakeDirectory for: "
+ << testNewLongDir << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true))
+ {
+ kwsys_ios::cerr
+ << "Problem with Touch for: "
+ << testNewLongFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::RemoveFile(testNewLongFile))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveFile: "
+ << testNewLongFile << kwsys_ios::endl;
+ res = false;
+ }
+
+ kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
+ if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir))
+ {
+ kwsys_ios::cerr
+ << "Problem with RemoveADirectory for: "
+ << testNewLongDir << kwsys_ios::endl;
+ res = false;
}
+#endif
return res;
}
@@ -138,7 +230,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with CapitalizedWords "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << '"' << test << '"' << kwsys_ios::endl;
res = false;
}
@@ -148,7 +240,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with UnCapitalizedWords "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << '"' << test << '"' << kwsys_ios::endl;
res = false;
}
@@ -158,7 +250,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with AddSpaceBetweenCapitalizedWords "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << '"' << test << '"' << kwsys_ios::endl;
res = false;
}
@@ -168,7 +260,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with AppendStrings "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A\" \" Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres;
@@ -179,7 +271,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with AppendStrings "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had\" \" A \" \"Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres;
@@ -188,7 +280,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with CountChar "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
@@ -198,7 +290,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with RemoveChars "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres;
@@ -209,7 +301,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with RemoveCharsButUpperHex "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres;
@@ -221,7 +313,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with ReplaceChars "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres2;
@@ -231,7 +323,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with StringStartsWith "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
@@ -240,7 +332,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with StringEndsWith "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
@@ -249,7 +341,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with DuplicateString "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
delete [] cres;
@@ -260,7 +352,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with CropString "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
res = false;
}
@@ -271,16 +363,124 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with Split "
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
- res = false;
+ << "\"Mary Had A Little Lamb.\"" << kwsys_ios::endl;
+ res = false;
+ }
+
+#ifdef _WIN32
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
+ L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
+ L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath
+ ("//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
+ L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
+ << kwsys_ios::endl;
+ res = false;
}
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") !=
+ L"//")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"//\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") !=
+ L"\\\\.\\")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") !=
+ L"\\\\.\\X")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") !=
+ L"\\\\?\\X:")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X:\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") !=
+ L"\\\\?\\X:\\")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"\\\\.\\X:\\\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") !=
+ L"\\\\.\\NUL")
+ {
+ kwsys_ios::cerr
+ << "Problem with ConvertToWindowsExtendedPath "
+ << "\"NUL\""
+ << kwsys_ios::endl;
+ res = false;
+ }
+
+#endif
+
if (kwsys::SystemTools::ConvertToWindowsOutputPath
("L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
"\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"")
{
kwsys_ios::cerr
<< "Problem with ConvertToWindowsOutputPath "
+ << "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\""
<< kwsys_ios::endl;
res = false;
}
@@ -291,6 +491,7 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with ConvertToWindowsOutputPath "
+ << "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\""
<< kwsys_ios::endl;
res = false;
}
@@ -301,29 +502,11 @@ static bool CheckStringOperations()
{
kwsys_ios::cerr
<< "Problem with ConvertToUnixOutputPath "
+ << "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\""
<< kwsys_ios::endl;
res = false;
}
- int targc;
- char **targv;
- kwsys::SystemTools::ConvertWindowsCommandLineToUnixArguments
- ("\"Local Mojo\\Voodoo.asp\" -CastHex \"D:\\My Secret Mojo\\Voodoo.mp3\"", &targc, &targv);
- if (targc != 4 || strcmp(targv[1],"Local Mojo\\Voodoo.asp") ||
- strcmp(targv[2],"-CastHex") ||
- strcmp(targv[3],"D:\\My Secret Mojo\\Voodoo.mp3"))
- {
- kwsys_ios::cerr
- << "Problem with ConvertWindowsCommandLineToUnixArguments"
- << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
- res = false;
- }
- for (;targc >=0; --targc)
- {
- delete [] targv[targc];
- }
- delete [] targv;
-
return res;
}
@@ -379,6 +562,55 @@ static bool CheckEnvironmentOperations()
return res;
}
+
+static bool CheckRelativePath(
+ const kwsys_stl::string& local,
+ const kwsys_stl::string& remote,
+ const kwsys_stl::string& expected)
+{
+ kwsys_stl::string result = kwsys::SystemTools::RelativePath(local, remote);
+ if(expected != result)
+ {
+ kwsys_ios::cerr << "RelativePath(" << local << ", " << remote
+ << ") yielded " << result << " instead of " << expected << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckRelativePaths()
+{
+ bool res = true;
+ res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash");
+ res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin");
+ return res;
+}
+
+static bool CheckCollapsePath(
+ const kwsys_stl::string& path,
+ const kwsys_stl::string& expected)
+{
+ kwsys_stl::string result = kwsys::SystemTools::CollapseFullPath(path);
+ if(expected != result)
+ {
+ kwsys_ios::cerr << "CollapseFullPath(" << path
+ << ") yielded " << result << " instead of " << expected << kwsys_ios::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckCollapsePath()
+{
+ bool res = true;
+ res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
+ res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
+ return res;
+}
+
//----------------------------------------------------------------------------
int testSystemTools(int, char*[])
{
@@ -410,5 +642,9 @@ int testSystemTools(int, char*[])
res &= CheckEnvironmentOperations();
+ res &= CheckRelativePaths();
+
+ res &= CheckCollapsePath();
+
return res ? 0 : 1;
}
diff --git a/Source/kwsys/testSystemTools.h.in b/Source/kwsys/testSystemTools.h.in
index 4b94bb6..66f0f72 100644
--- a/Source/kwsys/testSystemTools.h.in
+++ b/Source/kwsys/testSystemTools.h.in
@@ -14,7 +14,8 @@
#define EXECUTABLE_OUTPUT_PATH "@CMAKE_CURRENT_BINARY_DIR@"
-#define TEST_SYSTEMTOOLS_BIN_FILE "@TEST_SYSTEMTOOLS_BIN_FILE@"
-#define TEST_SYSTEMTOOLS_SRC_FILE "@TEST_SYSTEMTOOLS_SRC_FILE@"
+#define TEST_SYSTEMTOOLS_SOURCE_DIR "@TEST_SYSTEMTOOLS_SOURCE_DIR@"
+#define TEST_SYSTEMTOOLS_BINARY_DIR "@TEST_SYSTEMTOOLS_BINARY_DIR@"
+#cmakedefine KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
#endif