Merge branch 'upstream-kwsys' into update-kwsys

This commit is contained in:
Brad King 2014-10-31 13:11:58 -04:00
commit 5868b4e2fb
9 changed files with 250 additions and 135 deletions

View File

@ -265,7 +265,7 @@ STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}"
KWSYS_IN_SOURCE_BUILD) KWSYS_IN_SOURCE_BUILD)
IF(NOT KWSYS_IN_SOURCE_BUILD) IF(NOT KWSYS_IN_SOURCE_BUILD)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsysPrivate.h CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/kwsysPrivate.h
${PROJECT_BINARY_DIR}/kwsysPrivate.h COPY_ONLY IMMEDIATE) ${PROJECT_BINARY_DIR}/kwsysPrivate.h COPYONLY IMMEDIATE)
ENDIF(NOT KWSYS_IN_SOURCE_BUILD) ENDIF(NOT KWSYS_IN_SOURCE_BUILD)
# Select plugin module file name convention. # Select plugin module file name convention.
@ -1075,7 +1075,7 @@ ENDIF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}") ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
# Disable deprecation warnings for standard C functions. # Disable deprecation warnings for standard C functions.
IF(MSVC OR (WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")) IF(MSVC OR (WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel"))
ADD_DEFINITIONS( ADD_DEFINITIONS(
-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE
@ -1232,7 +1232,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
ENDFOREACH(n) ENDFOREACH(n)
# Some Apple compilers produce bad optimizations in this source. # Some Apple compilers produce bad optimizations in this source.
IF(APPLE AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|LLVM)$") IF(APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(GNU|LLVM)$")
SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0) SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL") ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL")
# Tell IBM XL not to warn about our test infinite loop # Tell IBM XL not to warn about our test infinite loop

View File

@ -18,7 +18,6 @@
/* Define these macros temporarily to keep the code readable. */ /* Define these macros temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl # define kwsys_stl @KWSYS_NAMESPACE@_stl
# define kwsys_ios @KWSYS_NAMESPACE@_ios
#endif #endif
namespace @KWSYS_NAMESPACE@ namespace @KWSYS_NAMESPACE@
@ -87,7 +86,6 @@ private:
/* Undefine temporary macros. */ /* Undefine temporary macros. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl # undef kwsys_stl
# undef kwsys_ios
#endif #endif
#endif #endif

View File

@ -40,9 +40,9 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
return shl_load(libname, BIND_DEFERRED | DYNAMIC_PATH, 0L); return shl_load(libname.c_str(), BIND_DEFERRED | DYNAMIC_PATH, 0L);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -53,7 +53,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::SymbolPointer
DynamicLoader::GetSymbolAddress(DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::GetSymbolAddress(DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
void* addr; void* addr;
int status; int status;
@ -62,7 +62,7 @@ DynamicLoader::GetSymbolAddress(DynamicLoader::LibraryHandle lib, const char* sy
* TYPE_DATA Look for a symbol in the data segment (for example, variables). * TYPE_DATA Look for a symbol in the data segment (for example, variables).
* TYPE_UNDEFINED Look for any symbol. * TYPE_UNDEFINED Look for any symbol.
*/ */
status = shl_findsym (&lib, sym, TYPE_UNDEFINED, &addr); status = shl_findsym (&lib, sym.c_str(), TYPE_UNDEFINED, &addr);
void* result = (status < 0) ? (void*)0 : addr; void* result = (status < 0) ? (void*)0 : addr;
// Hack to cast pointer-to-data to pointer-to-function. // Hack to cast pointer-to-data to pointer-to-function.
@ -111,18 +111,18 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
NSObjectFileImageReturnCode rc; NSObjectFileImageReturnCode rc;
NSObjectFileImage image = 0; NSObjectFileImage image = 0;
rc = NSCreateObjectFileImageFromFile(libname, &image); rc = NSCreateObjectFileImageFromFile(libname.c_str(), &image);
// rc == NSObjectFileImageInappropriateFile when trying to load a dylib file // rc == NSObjectFileImageInappropriateFile when trying to load a dylib file
if( rc != NSObjectFileImageSuccess ) if( rc != NSObjectFileImageSuccess )
{ {
return 0; return 0;
} }
NSModule handle = NSLinkModule(image, libname, NSModule handle = NSLinkModule(image, libname.c_str(),
NSLINKMODULE_OPTION_BINDNOW|NSLINKMODULE_OPTION_RETURN_ON_ERROR); NSLINKMODULE_OPTION_BINDNOW|NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(image); NSDestroyObjectFileImage(image);
return handle; return handle;
@ -142,14 +142,14 @@ int DynamicLoader::CloseLibrary( DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
void *result=0; void *result=0;
// Need to prepend symbols with '_' on Apple-gcc compilers // Need to prepend symbols with '_' on Apple-gcc compilers
size_t len = strlen(sym); size_t len = sym.size();
char *rsym = new char[len + 1 + 1]; char *rsym = new char[len + 1 + 1];
strcpy(rsym, "_"); strcpy(rsym, "_");
strcat(rsym+1, sym); strcat(rsym+1, sym.c_str());
NSSymbol symbol = NSLookupSymbolInModule(lib, rsym); NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
if(symbol) if(symbol)
@ -183,13 +183,13 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname)
{ {
DynamicLoader::LibraryHandle lh; DynamicLoader::LibraryHandle lh;
int length = MultiByteToWideChar(CP_UTF8, 0, libname, -1, NULL, 0); int length = MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, NULL, 0);
wchar_t* wchars = new wchar_t[length+1]; wchar_t* wchars = new wchar_t[length+1];
wchars[0] = '\0'; wchars[0] = '\0';
MultiByteToWideChar(CP_UTF8, 0, libname, -1, wchars, length); MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, wchars, length);
lh = LoadLibraryW(wchars); lh = LoadLibraryW(wchars);
delete [] wchars; delete [] wchars;
return lh; return lh;
@ -203,7 +203,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
// TODO: The calling convention affects the name of the symbol. We // TODO: The calling convention affects the name of the symbol. We
// should have a tool to help get the symbol with the desired // should have a tool to help get the symbol with the desired
@ -230,12 +230,12 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
void *result; void *result;
#if defined(__BORLANDC__) || defined(__WATCOMC__) #if defined(__BORLANDC__) || defined(__WATCOMC__)
// Need to prepend symbols with '_' // Need to prepend symbols with '_'
size_t len = strlen(sym); size_t len = sym.size();
char *rsym = new char[len + 1 + 1]; char *rsym = new char[len + 1 + 1];
strcpy(rsym, "_"); strcpy(rsym, "_");
strcat(rsym, sym); strcat(rsym, sym.c_str());
#else #else
const char *rsym = sym; const char *rsym = sym.c_str();
#endif #endif
result = (void*)GetProcAddress(lib, rsym); result = (void*)GetProcAddress(lib, rsym);
#if defined(__BORLANDC__) || defined(__WATCOMC__) #if defined(__BORLANDC__) || defined(__WATCOMC__)
@ -298,11 +298,11 @@ namespace KWSYS_NAMESPACE
static image_id last_dynamic_err = B_OK; static image_id last_dynamic_err = B_OK;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
// image_id's are integers, errors are negative. Add one just in case we // image_id's are integers, errors are negative. Add one just in case we
// get a valid image_id of zero (is that even possible?). // get a valid image_id of zero (is that even possible?).
image_id rc = load_add_on(libname); image_id rc = load_add_on(libname.c_str());
if (rc < 0) if (rc < 0)
{ {
last_dynamic_err = rc; last_dynamic_err = rc;
@ -336,7 +336,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
// Hack to cast pointer-to-data to pointer-to-function. // Hack to cast pointer-to-data to pointer-to-function.
union union
@ -356,7 +356,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
// !!! FIXME: BeOS can do function-only lookups...does this ever // !!! FIXME: BeOS can do function-only lookups...does this ever
// !!! FIXME: actually _want_ a data symbol lookup, or was this union // !!! FIXME: actually _want_ a data symbol lookup, or was this union
// !!! FIXME: a leftover of dlsym()? (s/ANY/TEXT for functions only). // !!! FIXME: a leftover of dlsym()? (s/ANY/TEXT for functions only).
status_t rc = get_image_symbol(lib-1,sym,B_SYMBOL_TYPE_ANY,&result.pvoid); status_t rc = get_image_symbol(lib-1,sym.c_str(),B_SYMBOL_TYPE_ANY,&result.pvoid);
if (rc != B_OK) if (rc != B_OK)
{ {
last_dynamic_err = rc; last_dynamic_err = rc;
@ -389,7 +389,7 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
return 0; return 0;
} }
@ -407,7 +407,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
return 0; return 0;
} }
@ -433,12 +433,12 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
char *name = (char *)calloc(1, strlen(libname) + 1); char *name = (char *)calloc(1, libname.size() + 1);
dld_init(program_invocation_name); dld_init(program_invocation_name);
strncpy(name, libname, strlen(libname)); strncpy(name, libname.c_str(), libname.size());
dld_link(libname); dld_link(libname.c_str());
return (void *)name; return (void *)name;
} }
@ -452,7 +452,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
// Hack to cast pointer-to-data to pointer-to-function. // Hack to cast pointer-to-data to pointer-to-function.
union union
@ -460,7 +460,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
void* pvoid; void* pvoid;
DynamicLoader::SymbolPointer psym; DynamicLoader::SymbolPointer psym;
} result; } result;
result.pvoid = dld_get_symbol(sym); result.pvoid = dld_get_symbol(sym.c_str());
return result.psym; return result.psym;
} }
@ -485,9 +485,9 @@ namespace KWSYS_NAMESPACE
{ {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname ) DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const kwsys_stl::string& libname )
{ {
return dlopen(libname, RTLD_LAZY); return dlopen(libname.c_str(), RTLD_LAZY);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -504,7 +504,7 @@ int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress( DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
DynamicLoader::LibraryHandle lib, const char* sym) DynamicLoader::LibraryHandle lib, const kwsys_stl::string& sym)
{ {
// Hack to cast pointer-to-data to pointer-to-function. // Hack to cast pointer-to-data to pointer-to-function.
union union
@ -512,7 +512,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
void* pvoid; void* pvoid;
DynamicLoader::SymbolPointer psym; DynamicLoader::SymbolPointer psym;
} result; } result;
result.pvoid = dlsym(lib, sym); result.pvoid = dlsym(lib, sym.c_str());
return result.psym; return result.psym;
} }

View File

@ -13,6 +13,7 @@
#define @KWSYS_NAMESPACE@_DynamicLoader_hxx #define @KWSYS_NAMESPACE@_DynamicLoader_hxx
#include <@KWSYS_NAMESPACE@/Configure.h> #include <@KWSYS_NAMESPACE@/Configure.h>
#include <@KWSYS_NAMESPACE@/stl/string>
#if defined(__hpux) #if defined(__hpux)
#include <dl.h> #include <dl.h>
@ -27,6 +28,11 @@
#include <be/kernel/image.h> #include <be/kernel/image.h>
#endif #endif
/* Define these macros temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
#endif
namespace @KWSYS_NAMESPACE@ namespace @KWSYS_NAMESPACE@
{ {
/** \class DynamicLoader /** \class DynamicLoader
@ -77,14 +83,14 @@ public:
/** Load a dynamic library into the current process. /** Load a dynamic library into the current process.
* The returned LibraryHandle can be used to access the symbols in the * The returned LibraryHandle can be used to access the symbols in the
* library. */ * library. */
static LibraryHandle OpenLibrary(const char*); static LibraryHandle OpenLibrary(const kwsys_stl::string&);
/** Attempt to detach a dynamic library from the /** Attempt to detach a dynamic library from the
* process. A value of true is returned if it is sucessful. */ * process. A value of true is returned if it is sucessful. */
static int CloseLibrary(LibraryHandle); static int CloseLibrary(LibraryHandle);
/** Find the address of the symbol in the given library. */ /** Find the address of the symbol in the given library. */
static SymbolPointer GetSymbolAddress(LibraryHandle, const char*); static SymbolPointer GetSymbolAddress(LibraryHandle, const kwsys_stl::string&);
/** Return the default module prefix for the current platform. */ /** Return the default module prefix for the current platform. */
static const char* LibPrefix() { return "@KWSYS_DynamicLoader_PREFIX@"; } static const char* LibPrefix() { return "@KWSYS_DynamicLoader_PREFIX@"; }
@ -98,4 +104,9 @@ public:
} // namespace @KWSYS_NAMESPACE@ } // namespace @KWSYS_NAMESPACE@
/* Undefine temporary macros. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#endif
#endif #endif

View File

@ -501,7 +501,7 @@ void Glob::AddFile(kwsys_stl::vector<kwsys_stl::string>& files, const kwsys_stl:
{ {
if ( !this->Relative.empty() ) if ( !this->Relative.empty() )
{ {
files.push_back(kwsys::SystemTools::RelativePath(this->Relative.c_str(), file.c_str())); files.push_back(kwsys::SystemTools::RelativePath(this->Relative, file));
} }
else else
{ {

View File

@ -5156,7 +5156,7 @@ bool SystemInformationImplementation::QueryOSInformation()
} }
} }
sprintf (operatingSystem, "%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); sprintf (operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
this->OSVersion = operatingSystem; this->OSVersion = operatingSystem;
} }
else else
@ -5205,7 +5205,7 @@ bool SystemInformationImplementation::QueryOSInformation()
if (osvi.dwMajorVersion <= 4) if (osvi.dwMajorVersion <= 4)
{ {
// NB: NT 4.0 and earlier. // NB: NT 4.0 and earlier.
sprintf (operatingSystem, "version %ld.%ld %s (Build %ld)", sprintf (operatingSystem, "version %ld.%ld %ls (Build %ld)",
osvi.dwMajorVersion, osvi.dwMajorVersion,
osvi.dwMinorVersion, osvi.dwMinorVersion,
osvi.szCSDVersion, osvi.szCSDVersion,
@ -5236,7 +5236,7 @@ bool SystemInformationImplementation::QueryOSInformation()
else else
{ {
// Windows 2000 and everything else. // Windows 2000 and everything else.
sprintf (operatingSystem,"%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); sprintf (operatingSystem,"%ls (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
this->OSVersion = operatingSystem; this->OSVersion = operatingSystem;
} }
break; break;

View File

@ -222,7 +222,7 @@ inline int Rmdir(const kwsys_stl::string& dir)
inline const char* Getcwd(char* buf, unsigned int len) inline const char* Getcwd(char* buf, unsigned int len)
{ {
std::vector<wchar_t> w_buf(len); std::vector<wchar_t> w_buf(len);
if(const wchar_t* ret = _wgetcwd(&w_buf[0], len)) if(_wgetcwd(&w_buf[0], len))
{ {
// make sure the drive letter is capital // make sure the drive letter is capital
if(wcslen(&w_buf[0]) > 1 && w_buf[1] == L':') if(wcslen(&w_buf[0]) > 1 && w_buf[1] == L':')
@ -385,6 +385,11 @@ const char* SystemTools::GetEnv(const char* key)
return getenv(key); return getenv(key);
} }
const char* SystemTools::GetEnv(const kwsys_stl::string& key)
{
return SystemTools::GetEnv(key.c_str());
}
bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result) bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result)
{ {
const char* v = getenv(key); const char* v = getenv(key);
@ -399,6 +404,11 @@ bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result)
} }
} }
bool SystemTools::GetEnv(const kwsys_stl::string& key, kwsys_stl::string& result)
{
return SystemTools::GetEnv(key.c_str(), result);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#if defined(__CYGWIN__) || defined(__GLIBC__) #if defined(__CYGWIN__) || defined(__GLIBC__)
@ -410,27 +420,28 @@ bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result)
#if KWSYS_CXX_HAS_UNSETENV #if KWSYS_CXX_HAS_UNSETENV
/* unsetenv("A") removes A from the environment. /* unsetenv("A") removes A from the environment.
On older platforms it returns void instead of int. */ On older platforms it returns void instead of int. */
static int kwsysUnPutEnv(const char* env) static int kwsysUnPutEnv(const kwsys_stl::string& env)
{ {
if(const char* eq = strchr(env, '=')) size_t pos = env.find('=');
if(pos != env.npos)
{ {
std::string name(env, eq-env); std::string name = env.substr(0, pos);
unsetenv(name.c_str()); unsetenv(name.c_str());
} }
else else
{ {
unsetenv(env); unsetenv(env.c_str());
} }
return 0; return 0;
} }
#elif defined(KWSYS_PUTENV_EMPTY) || defined(KWSYS_PUTENV_NAME) #elif defined(KWSYS_PUTENV_EMPTY) || defined(KWSYS_PUTENV_NAME)
/* putenv("A=") or putenv("A") removes A from the environment. */ /* putenv("A=") or putenv("A") removes A from the environment. */
static int kwsysUnPutEnv(const char* env) static int kwsysUnPutEnv(const kwsys_stl::string& env)
{ {
int err = 0; int err = 0;
const char* eq = strchr(env, '='); size_t pos = env.find('=');
size_t const len = eq? (size_t)(eq-env) : strlen(env); size_t const len = pos == env.npos ? env.size() : pos;
# ifdef KWSYS_PUTENV_EMPTY # ifdef KWSYS_PUTENV_EMPTY
size_t const sz = len + 2; size_t const sz = len + 2;
# else # else
@ -442,7 +453,7 @@ static int kwsysUnPutEnv(const char* env)
{ {
return -1; return -1;
} }
strncpy(buf, env, len); strncpy(buf, env.c_str(), len);
# ifdef KWSYS_PUTENV_EMPTY # ifdef KWSYS_PUTENV_EMPTY
buf[len] = '='; buf[len] = '=';
buf[len+1] = 0; buf[len+1] = 0;
@ -471,17 +482,17 @@ static int kwsysUnPutEnv(const char* env)
#else #else
/* Manipulate the "environ" global directly. */ /* Manipulate the "environ" global directly. */
static int kwsysUnPutEnv(const char* env) static int kwsysUnPutEnv(const kwsys_stl::string& env)
{ {
const char* eq = strchr(env, '='); size_t pos = env.find('=');
size_t const len = eq? (size_t)(eq-env) : strlen(env); size_t const len = pos == env.npos ? env.size() : pos;
int in = 0; int in = 0;
int out = 0; int out = 0;
while(environ[in]) while(environ[in])
{ {
if(strlen(environ[in]) > len && if(strlen(environ[in]) > len &&
environ[in][len] == '=' && environ[in][len] == '=' &&
strncmp(env, environ[in], len) == 0) strncmp(env.c_str(), environ[in], len) == 0)
{ {
++in; ++in;
} }
@ -504,12 +515,13 @@ static int kwsysUnPutEnv(const char* env)
/* setenv("A", "B", 1) will set A=B in the environment and makes its /* setenv("A", "B", 1) will set A=B in the environment and makes its
own copies of the strings. */ own copies of the strings. */
bool SystemTools::PutEnv(const char* env) bool SystemTools::PutEnv(const kwsys_stl::string& env)
{ {
if(const char* eq = strchr(env, '=')) size_t pos = env.find('=');
if(pos != env.npos)
{ {
std::string name(env, eq-env); std::string name = env.substr(0, pos);
return setenv(name.c_str(), eq+1, 1) == 0; return setenv(name.c_str(), env.c_str() + pos + 1, 1) == 0;
} }
else else
{ {
@ -517,7 +529,7 @@ bool SystemTools::PutEnv(const char* env)
} }
} }
bool SystemTools::UnPutEnv(const char* env) bool SystemTools::UnPutEnv(const kwsys_stl::string& env)
{ {
return kwsysUnPutEnv(env) == 0; return kwsysUnPutEnv(env) == 0;
} }
@ -603,14 +615,14 @@ public:
static kwsysEnv kwsysEnvInstance; static kwsysEnv kwsysEnvInstance;
bool SystemTools::PutEnv(const char* env) bool SystemTools::PutEnv(const kwsys_stl::string& env)
{ {
return kwsysEnvInstance.Put(env); return kwsysEnvInstance.Put(env.c_str());
} }
bool SystemTools::UnPutEnv(const char* env) bool SystemTools::UnPutEnv(const kwsys_stl::string& env)
{ {
return kwsysEnvInstance.UnPut(env); return kwsysEnvInstance.UnPut(env.c_str());
} }
#endif #endif
@ -689,8 +701,35 @@ bool SystemTools::MakeDirectory(const kwsys_stl::string& path)
// replace replace with with as many times as it shows up in source. // replace replace with with as many times as it shows up in source.
// write the result into source. // write the result into source.
void SystemTools::ReplaceString(kwsys_stl::string& source, void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace, const kwsys_stl::string& replace,
const char* with) const kwsys_stl::string& with)
{
// do while hangs if replaceSize is 0
if (replace.empty())
{
return;
}
SystemTools::ReplaceString(source, replace.c_str(), replace.size(), with);
}
void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace,
const char* with)
{
// do while hangs if replaceSize is 0
if (!*replace)
{
return;
}
SystemTools::ReplaceString(source, replace, strlen(replace), with ? with : "");
}
void SystemTools::ReplaceString(kwsys_stl::string& source,
const char* replace,
size_t replaceSize,
const kwsys_stl::string& with)
{ {
const char *src = source.c_str(); const char *src = source.c_str();
char *searchPos = const_cast<char *>(strstr(src,replace)); char *searchPos = const_cast<char *>(strstr(src,replace));
@ -702,12 +741,6 @@ void SystemTools::ReplaceString(kwsys_stl::string& source,
} }
// perform replacements until done // perform replacements until done
size_t replaceSize = strlen(replace);
// do while hangs if replaceSize is 0
if(replaceSize == 0)
{
return;
}
char *orig = strdup(src); char *orig = strdup(src);
char *currentPos = orig; char *currentPos = orig;
searchPos = searchPos - src + orig; searchPos = searchPos - src + orig;
@ -739,20 +772,20 @@ void SystemTools::ReplaceString(kwsys_stl::string& source,
#endif #endif
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
static bool SystemToolsParseRegistryKey(const char* key, static bool SystemToolsParseRegistryKey(const kwsys_stl::string& key,
HKEY& primaryKey, HKEY& primaryKey,
kwsys_stl::string& second, kwsys_stl::string& second,
kwsys_stl::string& valuename) kwsys_stl::string& valuename)
{ {
kwsys_stl::string primary = key; kwsys_stl::string primary = key;
size_t start = primary.find("\\"); size_t start = primary.find('\\');
if (start == kwsys_stl::string::npos) if (start == kwsys_stl::string::npos)
{ {
return false; return false;
} }
size_t valuenamepos = primary.find(";"); size_t valuenamepos = primary.find(';');
if (valuenamepos != kwsys_stl::string::npos) if (valuenamepos != kwsys_stl::string::npos)
{ {
valuename = primary.substr(valuenamepos+1); valuename = primary.substr(valuenamepos+1);
@ -810,7 +843,7 @@ static DWORD SystemToolsMakeRegistryMode(DWORD mode,
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool bool
SystemTools::GetRegistrySubKeys(const char *key, SystemTools::GetRegistrySubKeys(const kwsys_stl::string& key,
kwsys_stl::vector<kwsys_stl::string>& subkeys, kwsys_stl::vector<kwsys_stl::string>& subkeys,
KeyWOW64 view) KeyWOW64 view)
{ {
@ -849,7 +882,7 @@ SystemTools::GetRegistrySubKeys(const char *key,
return true; return true;
} }
#else #else
bool SystemTools::GetRegistrySubKeys(const char *, bool SystemTools::GetRegistrySubKeys(const kwsys_stl::string&,
kwsys_stl::vector<kwsys_stl::string>&, kwsys_stl::vector<kwsys_stl::string>&,
KeyWOW64) KeyWOW64)
{ {
@ -865,7 +898,7 @@ bool SystemTools::GetRegistrySubKeys(const char *,
// => will return the data of the "Root" value of the key // => will return the data of the "Root" value of the key
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value, bool SystemTools::ReadRegistryValue(const kwsys_stl::string& key, kwsys_stl::string &value,
KeyWOW64 view) KeyWOW64 view)
{ {
bool valueset = false; bool valueset = false;
@ -922,7 +955,7 @@ bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value,
return valueset; return valueset;
} }
#else #else
bool SystemTools::ReadRegistryValue(const char *, kwsys_stl::string &, bool SystemTools::ReadRegistryValue(const kwsys_stl::string&, kwsys_stl::string &,
KeyWOW64) KeyWOW64)
{ {
return false; return false;
@ -938,7 +971,8 @@ bool SystemTools::ReadRegistryValue(const char *, kwsys_stl::string &,
// => will set the data of the "Root" value of the key // => will set the data of the "Root" value of the key
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::WriteRegistryValue(const char *key, const char *value, bool SystemTools::WriteRegistryValue(const kwsys_stl::string& key,
const kwsys_stl::string& value,
KeyWOW64 view) KeyWOW64 view)
{ {
HKEY primaryKey = HKEY_CURRENT_USER; HKEY primaryKey = HKEY_CURRENT_USER;
@ -978,7 +1012,7 @@ bool SystemTools::WriteRegistryValue(const char *key, const char *value,
return false; return false;
} }
#else #else
bool SystemTools::WriteRegistryValue(const char *, const char *, KeyWOW64) bool SystemTools::WriteRegistryValue(const kwsys_stl::string&, const kwsys_stl::string&, KeyWOW64)
{ {
return false; return false;
} }
@ -992,7 +1026,7 @@ bool SystemTools::WriteRegistryValue(const char *, const char *, KeyWOW64)
// => will delete the data of the "Root" value of the key // => will delete the data of the "Root" value of the key
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::DeleteRegistryValue(const char *key, KeyWOW64 view) bool SystemTools::DeleteRegistryValue(const kwsys_stl::string& key, KeyWOW64 view)
{ {
HKEY primaryKey = HKEY_CURRENT_USER; HKEY primaryKey = HKEY_CURRENT_USER;
kwsys_stl::string second; kwsys_stl::string second;
@ -1023,7 +1057,7 @@ bool SystemTools::DeleteRegistryValue(const char *key, KeyWOW64 view)
return false; return false;
} }
#else #else
bool SystemTools::DeleteRegistryValue(const char *, KeyWOW64) bool SystemTools::DeleteRegistryValue(const kwsys_stl::string&, KeyWOW64)
{ {
return false; return false;
} }
@ -2245,12 +2279,13 @@ bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_st
SystemTools::MakeDirectory(destination_dir); SystemTools::MakeDirectory(destination_dir);
// Open files // Open files
#if defined(_WIN32)
#if defined(_WIN32) || defined(__CYGWIN__) kwsys::ifstream fin(Encoding::ToNarrow(
kwsys::ifstream fin(source.c_str(), SystemTools::ConvertToWindowsExtendedPath(source)).c_str(),
kwsys_ios::ios::binary | kwsys_ios::ios::in); kwsys_ios::ios::in | kwsys_ios_binary);
#else #else
kwsys::ifstream fin(source.c_str()); kwsys::ifstream fin(source.c_str(),
kwsys_ios::ios::in | kwsys_ios_binary);
#endif #endif
if(!fin) if(!fin)
{ {
@ -2263,12 +2298,13 @@ bool SystemTools::CopyFileAlways(const kwsys_stl::string& source, const kwsys_st
// that do not allow file removal can be modified. // that do not allow file removal can be modified.
SystemTools::RemoveFile(real_destination); SystemTools::RemoveFile(real_destination);
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32)
kwsys::ofstream fout(real_destination.c_str(), kwsys::ofstream fout(Encoding::ToNarrow(
kwsys_ios::ios::binary | kwsys_ios::ios::out | kwsys_ios::ios::trunc); SystemTools::ConvertToWindowsExtendedPath(real_destination)).c_str(),
kwsys_ios::ios::out | kwsys_ios::ios::trunc | kwsys_ios_binary);
#else #else
kwsys::ofstream fout(real_destination.c_str(), kwsys::ofstream fout(real_destination.c_str(),
kwsys_ios::ios::out | kwsys_ios::ios::trunc); kwsys_ios::ios::out | kwsys_ios::ios::trunc | kwsys_ios_binary);
#endif #endif
if(!fout) if(!fout)
{ {
@ -2379,7 +2415,7 @@ bool SystemTools::CopyADirectory(const kwsys_stl::string& source, const kwsys_st
// return size of file; also returns zero if no file exists // return size of file; also returns zero if no file exists
unsigned long SystemTools::FileLength(const char* filename) unsigned long SystemTools::FileLength(const kwsys_stl::string& filename)
{ {
unsigned long length = 0; unsigned long length = 0;
#ifdef _WIN32 #ifdef _WIN32
@ -2397,7 +2433,7 @@ unsigned long SystemTools::FileLength(const char* filename)
} }
#else #else
struct stat fs; struct stat fs;
if (stat(filename, &fs) == 0) if (stat(filename.c_str(), &fs) == 0)
{ {
length = static_cast<unsigned long>(fs.st_size); length = static_cast<unsigned long>(fs.st_size);
} }
@ -2663,7 +2699,7 @@ size_t SystemTools::GetMaximumFilePathLength()
* found. Otherwise, the empty string is returned. * found. Otherwise, the empty string is returned.
*/ */
kwsys_stl::string SystemTools kwsys_stl::string SystemTools
::FindName(const char* name, ::FindName(const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& userPaths, const kwsys_stl::vector<kwsys_stl::string>& userPaths,
bool no_system_path) bool no_system_path)
{ {
@ -2716,7 +2752,7 @@ kwsys_stl::string SystemTools
* found. Otherwise, the empty string is returned. * found. Otherwise, the empty string is returned.
*/ */
kwsys_stl::string SystemTools kwsys_stl::string SystemTools
::FindFile(const char* name, ::FindFile(const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& userPaths, const kwsys_stl::vector<kwsys_stl::string>& userPaths,
bool no_system_path) bool no_system_path)
{ {
@ -2735,7 +2771,7 @@ kwsys_stl::string SystemTools
* found. Otherwise, the empty string is returned. * found. Otherwise, the empty string is returned.
*/ */
kwsys_stl::string SystemTools kwsys_stl::string SystemTools
::FindDirectory(const char* name, ::FindDirectory(const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& userPaths, const kwsys_stl::vector<kwsys_stl::string>& userPaths,
bool no_system_path) bool no_system_path)
{ {
@ -3078,29 +3114,29 @@ bool SystemTools::FileIsSymlink(const kwsys_stl::string& name)
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::CreateSymlink(const char*, const char*) bool SystemTools::CreateSymlink(const kwsys_stl::string&, const kwsys_stl::string&)
{ {
return false; return false;
} }
#else #else
bool SystemTools::CreateSymlink(const char* origName, const char* newName) bool SystemTools::CreateSymlink(const kwsys_stl::string& origName, const kwsys_stl::string& newName)
{ {
return symlink(origName, newName) >= 0; return symlink(origName.c_str(), newName.c_str()) >= 0;
} }
#endif #endif
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::ReadSymlink(const char*, kwsys_stl::string&) bool SystemTools::ReadSymlink(const kwsys_stl::string&, kwsys_stl::string&)
{ {
return false; return false;
} }
#else #else
bool SystemTools::ReadSymlink(const char* newName, bool SystemTools::ReadSymlink(const kwsys_stl::string& newName,
kwsys_stl::string& origName) kwsys_stl::string& origName)
{ {
char buf[KWSYS_SYSTEMTOOLS_MAXPATH+1]; char buf[KWSYS_SYSTEMTOOLS_MAXPATH+1];
int count = int count =
static_cast<int>(readlink(newName, buf, KWSYS_SYSTEMTOOLS_MAXPATH)); static_cast<int>(readlink(newName.c_str(), buf, KWSYS_SYSTEMTOOLS_MAXPATH));
if(count >= 0) if(count >= 0)
{ {
// Add null-terminator. // Add null-terminator.
@ -3136,14 +3172,14 @@ kwsys_stl::string SystemTools::GetCurrentWorkingDirectory(bool collapse)
return path; return path;
} }
kwsys_stl::string SystemTools::GetProgramPath(const char* in_name) kwsys_stl::string SystemTools::GetProgramPath(const kwsys_stl::string& in_name)
{ {
kwsys_stl::string dir, file; kwsys_stl::string dir, file;
SystemTools::SplitProgramPath(in_name, dir, file); SystemTools::SplitProgramPath(in_name, dir, file);
return dir; return dir;
} }
bool SystemTools::SplitProgramPath(const char* in_name, bool SystemTools::SplitProgramPath(const kwsys_stl::string& in_name,
kwsys_stl::string& dir, kwsys_stl::string& dir,
kwsys_stl::string& file, kwsys_stl::string& file,
bool) bool)
@ -3409,7 +3445,62 @@ kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path
SystemTools::CheckTranslationPath(newPath); SystemTools::CheckTranslationPath(newPath);
#ifdef _WIN32 #ifdef _WIN32
newPath = SystemTools::GetActualCaseForPath(newPath.c_str()); newPath = SystemTools::GetActualCaseForPath(newPath);
SystemTools::ConvertToUnixSlashes(newPath);
#endif
// Return the reconstructed path.
return newPath;
}
kwsys_stl::string SystemTools::CollapseFullPath(const kwsys_stl::string& in_path,
const kwsys_stl::string& in_base)
{
// Collect the output path components.
kwsys_stl::vector<kwsys_stl::string> out_components;
// Split the input path components.
kwsys_stl::vector<kwsys_stl::string> path_components;
SystemTools::SplitPath(in_path, path_components);
// If the input path is relative, start with a base path.
if(path_components[0].length() == 0)
{
kwsys_stl::vector<kwsys_stl::string> base_components;
// Use the given base path.
SystemTools::SplitPath(in_base, base_components);
// Append base path components to the output path.
out_components.push_back(base_components[0]);
SystemToolsAppendComponents(out_components,
base_components.begin()+1,
base_components.end());
}
// Append input path components to the output path.
SystemToolsAppendComponents(out_components,
path_components.begin(),
path_components.end());
// Transform the path back to a string.
kwsys_stl::string newPath = SystemTools::JoinPath(out_components);
// Update the translation table with this potentially new path. I am not
// sure why this line is here, it seems really questionable, but yet I
// would put good money that if I remove it something will break, basically
// from what I can see it created a mapping from the collapsed path, to be
// replaced by the input path, which almost completely does the opposite of
// this function, the only thing preventing this from happening a lot is
// that if the in_path has a .. in it, then it is not added to the
// translation table. So for most calls this either does nothing due to the
// .. or it adds a translation between identical paths as nothing was
// collapsed, so I am going to try to comment it out, and see what hits the
// fan, hopefully quickly.
// Commented out line below:
//SystemTools::AddTranslationPath(newPath, in_path);
SystemTools::CheckTranslationPath(newPath);
#ifdef _WIN32
newPath = SystemTools::GetActualCaseForPath(newPath);
SystemTools::ConvertToUnixSlashes(newPath); SystemTools::ConvertToUnixSlashes(newPath);
#endif #endif
// Return the reconstructed path. // Return the reconstructed path.
@ -3569,7 +3660,7 @@ static int GetCasePathName(const kwsys_stl::string & pathIn,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
kwsys_stl::string SystemTools::GetActualCaseForPath(const char* p) kwsys_stl::string SystemTools::GetActualCaseForPath(const kwsys_stl::string& p)
{ {
#ifndef _WIN32 #ifndef _WIN32
return p; return p;
@ -3930,7 +4021,7 @@ kwsys_stl::string SystemTools::GetFilenameName(const kwsys_stl::string& filename
kwsys_stl::string SystemTools::GetFilenameExtension(const kwsys_stl::string& filename) kwsys_stl::string SystemTools::GetFilenameExtension(const kwsys_stl::string& filename)
{ {
kwsys_stl::string name = SystemTools::GetFilenameName(filename); kwsys_stl::string name = SystemTools::GetFilenameName(filename);
kwsys_stl::string::size_type dot_pos = name.find("."); kwsys_stl::string::size_type dot_pos = name.find('.');
if(dot_pos != kwsys_stl::string::npos) if(dot_pos != kwsys_stl::string::npos)
{ {
return name.substr(dot_pos); return name.substr(dot_pos);
@ -3948,7 +4039,7 @@ kwsys_stl::string SystemTools::GetFilenameExtension(const kwsys_stl::string& fil
kwsys_stl::string SystemTools::GetFilenameLastExtension(const kwsys_stl::string& filename) kwsys_stl::string SystemTools::GetFilenameLastExtension(const kwsys_stl::string& filename)
{ {
kwsys_stl::string name = SystemTools::GetFilenameName(filename); kwsys_stl::string name = SystemTools::GetFilenameName(filename);
kwsys_stl::string::size_type dot_pos = name.rfind("."); kwsys_stl::string::size_type dot_pos = name.rfind('.');
if(dot_pos != kwsys_stl::string::npos) if(dot_pos != kwsys_stl::string::npos)
{ {
return name.substr(dot_pos); return name.substr(dot_pos);
@ -3966,7 +4057,7 @@ kwsys_stl::string SystemTools::GetFilenameLastExtension(const kwsys_stl::string&
kwsys_stl::string SystemTools::GetFilenameWithoutExtension(const kwsys_stl::string& filename) kwsys_stl::string SystemTools::GetFilenameWithoutExtension(const kwsys_stl::string& filename)
{ {
kwsys_stl::string name = SystemTools::GetFilenameName(filename); kwsys_stl::string name = SystemTools::GetFilenameName(filename);
kwsys_stl::string::size_type dot_pos = name.find("."); kwsys_stl::string::size_type dot_pos = name.find('.');
if(dot_pos != kwsys_stl::string::npos) if(dot_pos != kwsys_stl::string::npos)
{ {
return name.substr(0, dot_pos); return name.substr(0, dot_pos);
@ -3987,7 +4078,7 @@ kwsys_stl::string
SystemTools::GetFilenameWithoutLastExtension(const kwsys_stl::string& filename) SystemTools::GetFilenameWithoutLastExtension(const kwsys_stl::string& filename)
{ {
kwsys_stl::string name = SystemTools::GetFilenameName(filename); kwsys_stl::string name = SystemTools::GetFilenameName(filename);
kwsys_stl::string::size_type dot_pos = name.rfind("."); kwsys_stl::string::size_type dot_pos = name.rfind('.');
if(dot_pos != kwsys_stl::string::npos) if(dot_pos != kwsys_stl::string::npos)
{ {
return name.substr(0, dot_pos); return name.substr(0, dot_pos);
@ -4276,7 +4367,7 @@ bool SystemTools::GetShortPath(const kwsys_stl::string& path, kwsys_stl::string&
#endif #endif
} }
void SystemTools::SplitProgramFromArgs(const char* path, void SystemTools::SplitProgramFromArgs(const kwsys_stl::string& path,
kwsys_stl::string& program, kwsys_stl::string& args) kwsys_stl::string& program, kwsys_stl::string& args)
{ {
// see if this is a full path to a program // see if this is a full path to a program
@ -4352,7 +4443,7 @@ kwsys_stl::string SystemTools::GetCurrentDateTime(const char* format)
return kwsys_stl::string(buf); return kwsys_stl::string(buf);
} }
kwsys_stl::string SystemTools::MakeCidentifier(const char* s) kwsys_stl::string SystemTools::MakeCidentifier(const kwsys_stl::string& s)
{ {
kwsys_stl::string str(s); kwsys_stl::string str(s);
if (str.find_first_of("0123456789") == 0) if (str.find_first_of("0123456789") == 0)

View File

@ -89,9 +89,9 @@ public:
* then an underscore is prepended. Note that this can produce * then an underscore is prepended. Note that this can produce
* identifiers that the standard reserves (_[A-Z].* and __.*). * identifiers that the standard reserves (_[A-Z].* and __.*).
*/ */
static kwsys_stl::string MakeCidentifier(const char* s); static kwsys_stl::string MakeCidentifier(const kwsys_stl::string& s);
static kwsys_stl::string MakeCindentifier(const char* s) static kwsys_stl::string MakeCindentifier(const kwsys_stl::string& s)
{ {
return MakeCidentifier(s); return MakeCidentifier(s);
} }
@ -102,6 +102,9 @@ public:
static void ReplaceString(kwsys_stl::string& source, static void ReplaceString(kwsys_stl::string& source,
const char* replace, const char* replace,
const char* with); const char* with);
static void ReplaceString(kwsys_stl::string& source,
const kwsys_stl::string& replace,
const kwsys_stl::string& with);
/** /**
* Return a capitalized string (i.e the first letter is uppercased, * Return a capitalized string (i.e the first letter is uppercased,
@ -306,7 +309,7 @@ public:
/** /**
* Return file length * Return file length
*/ */
static unsigned long FileLength(const char *filename); static unsigned long FileLength(const kwsys_stl::string& filename);
/** /**
Change the modification time or create a file Change the modification time or create a file
@ -335,15 +338,15 @@ public:
* does not exist path is returned unchanged. This does nothing * does not exist path is returned unchanged. This does nothing
* on unix but return path. * on unix but return path.
*/ */
static kwsys_stl::string GetActualCaseForPath(const char* path); static kwsys_stl::string GetActualCaseForPath(const kwsys_stl::string& path);
/** /**
* Given the path to a program executable, get the directory part of * Given the path to a program executable, get the directory part of
* the path with the file stripped off. If there is no directory * the path with the file stripped off. If there is no directory
* part, the empty string is returned. * part, the empty string is returned.
*/ */
static kwsys_stl::string GetProgramPath(const char*); static kwsys_stl::string GetProgramPath(const kwsys_stl::string&);
static bool SplitProgramPath(const char* in_name, static bool SplitProgramPath(const kwsys_stl::string& in_name,
kwsys_stl::string& dir, kwsys_stl::string& dir,
kwsys_stl::string& file, kwsys_stl::string& file,
bool errorReport = true); bool errorReport = true);
@ -376,6 +379,8 @@ public:
static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative); static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative);
static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative, static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative,
const char* in_base); const char* in_base);
static kwsys_stl::string CollapseFullPath(const kwsys_stl::string& in_relative,
const kwsys_stl::string& in_base);
/** /**
* Get the real path for a given path, removing all symlinks. In * Get the real path for a given path, removing all symlinks. In
@ -446,7 +451,7 @@ public:
* Split a program from its arguments and handle spaces in the paths * Split a program from its arguments and handle spaces in the paths
*/ */
static void SplitProgramFromArgs( static void SplitProgramFromArgs(
const char* path, const kwsys_stl::string& path,
kwsys_stl::string& program, kwsys_stl::string& args); kwsys_stl::string& program, kwsys_stl::string& args);
/** /**
@ -582,7 +587,7 @@ public:
* Find a file in the system PATH, with optional extra paths * Find a file in the system PATH, with optional extra paths
*/ */
static kwsys_stl::string FindFile( static kwsys_stl::string FindFile(
const char* name, const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& path = const kwsys_stl::vector<kwsys_stl::string>& path =
kwsys_stl::vector<kwsys_stl::string>(), kwsys_stl::vector<kwsys_stl::string>(),
bool no_system_path = false); bool no_system_path = false);
@ -591,7 +596,7 @@ public:
* Find a directory in the system PATH, with optional extra paths * Find a directory in the system PATH, with optional extra paths
*/ */
static kwsys_stl::string FindDirectory( static kwsys_stl::string FindDirectory(
const char* name, const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& path = const kwsys_stl::vector<kwsys_stl::string>& path =
kwsys_stl::vector<kwsys_stl::string>(), kwsys_stl::vector<kwsys_stl::string>(),
bool no_system_path = false); bool no_system_path = false);
@ -662,13 +667,13 @@ public:
* Create a symbolic link if the platform supports it. Returns whether * Create a symbolic link if the platform supports it. Returns whether
* creation succeded. * creation succeded.
*/ */
static bool CreateSymlink(const char* origName, const char* newName); static bool CreateSymlink(const kwsys_stl::string& origName, const kwsys_stl::string& newName);
/** /**
* Read the contents of a symbolic link. Returns whether reading * Read the contents of a symbolic link. Returns whether reading
* succeded. * succeded.
*/ */
static bool ReadSymlink(const char* newName, kwsys_stl::string& origName); static bool ReadSymlink(const kwsys_stl::string& newName, kwsys_stl::string& origName);
/** /**
* Try to locate the file 'filename' in the directory 'dir'. * Try to locate the file 'filename' in the directory 'dir'.
@ -750,26 +755,26 @@ public:
/** /**
* Get a list of subkeys. * Get a list of subkeys.
*/ */
static bool GetRegistrySubKeys(const char *key, static bool GetRegistrySubKeys(const kwsys_stl::string& key,
kwsys_stl::vector<kwsys_stl::string>& subkeys, kwsys_stl::vector<kwsys_stl::string>& subkeys,
KeyWOW64 view = KeyWOW64_Default); KeyWOW64 view = KeyWOW64_Default);
/** /**
* Read a registry value * Read a registry value
*/ */
static bool ReadRegistryValue(const char *key, kwsys_stl::string &value, static bool ReadRegistryValue(const kwsys_stl::string& key, kwsys_stl::string &value,
KeyWOW64 view = KeyWOW64_Default); KeyWOW64 view = KeyWOW64_Default);
/** /**
* Write a registry value * Write a registry value
*/ */
static bool WriteRegistryValue(const char *key, const char *value, static bool WriteRegistryValue(const kwsys_stl::string& key, const kwsys_stl::string& value,
KeyWOW64 view = KeyWOW64_Default); KeyWOW64 view = KeyWOW64_Default);
/** /**
* Delete a registry value * Delete a registry value
*/ */
static bool DeleteRegistryValue(const char *key, static bool DeleteRegistryValue(const kwsys_stl::string& key,
KeyWOW64 view = KeyWOW64_Default); KeyWOW64 view = KeyWOW64_Default);
/** ----------------------------------------------------------------- /** -----------------------------------------------------------------
@ -789,15 +794,17 @@ public:
* Read an environment variable * Read an environment variable
*/ */
static const char* GetEnv(const char* key); static const char* GetEnv(const char* key);
static const char* GetEnv(const kwsys_stl::string& key);
static bool GetEnv(const char* key, kwsys_stl::string& result); static bool GetEnv(const char* key, kwsys_stl::string& result);
static bool GetEnv(const kwsys_stl::string& key, kwsys_stl::string& result);
/** Put a string into the environment /** Put a string into the environment
of the form var=value */ of the form var=value */
static bool PutEnv(const char* env); static bool PutEnv(const kwsys_stl::string& env);
/** Remove a string from the environment. /** Remove a string from the environment.
Input is of the form "var" or "var=value" (value is ignored). */ Input is of the form "var" or "var=value" (value is ignored). */
static bool UnPutEnv(const char* env); static bool UnPutEnv(const kwsys_stl::string& env);
/** /**
* Get current working directory CWD * Get current working directory CWD
@ -905,6 +912,14 @@ private:
return &SystemToolsManagerInstance; return &SystemToolsManagerInstance;
} }
/**
* Actual implementation of ReplaceString.
*/
static void ReplaceString(kwsys_stl::string& source,
const char* replace,
size_t replaceSize,
const kwsys_stl::string& with);
/** /**
* Actual implementation of FileIsFullPath. * Actual implementation of FileIsFullPath.
*/ */
@ -915,7 +930,7 @@ private:
* optional extra paths. * optional extra paths.
*/ */
static kwsys_stl::string FindName( static kwsys_stl::string FindName(
const char* name, const kwsys_stl::string& name,
const kwsys_stl::vector<kwsys_stl::string>& path = const kwsys_stl::vector<kwsys_stl::string>& path =
kwsys_stl::vector<kwsys_stl::string>(), kwsys_stl::vector<kwsys_stl::string>(),
bool no_system_path = false); bool no_system_path = false);

View File

@ -124,7 +124,7 @@ static bool CheckFileOperations()
res = false; res = false;
} }
if (kwsys::SystemTools::FileLength(testBinFile.c_str()) != 766) if (kwsys::SystemTools::FileLength(testBinFile) != 766)
{ {
kwsys_ios::cerr kwsys_ios::cerr
<< "Problem with FileLength - incorrect length for: " << "Problem with FileLength - incorrect length for: "
@ -512,7 +512,7 @@ static bool CheckStringOperations()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
static bool CheckPutEnv(const char* env, const char* name, const char* value) static bool CheckPutEnv(const kwsys_stl::string& env, const char* name, const char* value)
{ {
if(!kwsys::SystemTools::PutEnv(env)) if(!kwsys::SystemTools::PutEnv(env))
{ {