Merge branch 'upstream-KWSys' into update-kwsys

* upstream-KWSys:
  KWSys 2016-07-18 (19732229)
This commit is contained in:
Brad King 2016-07-19 08:27:19 -04:00
commit 788bb14664
2 changed files with 19 additions and 28 deletions

View File

@ -490,14 +490,12 @@ void SystemTools::GetPath(std::vector<std::string>& path, const char* env)
{ {
env = "PATH"; env = "PATH";
} }
const char* cpathEnv = SystemTools::GetEnv(env); std::string pathEnv;
if ( !cpathEnv ) if ( !SystemTools::GetEnv(env, pathEnv) )
{ {
return; return;
} }
std::string pathEnv = cpathEnv;
// A hack to make the below algorithm work. // A hack to make the below algorithm work.
if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep) if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep)
{ {
@ -2132,8 +2130,8 @@ void SystemTools::ConvertToUnixSlashes(std::string& path)
pathCString = path.c_str(); pathCString = path.c_str();
if(pathCString[0] == '~' && (pathCString[1] == '/' || pathCString[1] == '\0')) if(pathCString[0] == '~' && (pathCString[1] == '/' || pathCString[1] == '\0'))
{ {
const char* homeEnv = SystemTools::GetEnv("HOME"); std::string homeEnv;
if (homeEnv) if (SystemTools::GetEnv("HOME", homeEnv))
{ {
path.replace(0,1,homeEnv); path.replace(0,1,homeEnv);
} }
@ -4149,16 +4147,9 @@ void SystemTools::SplitPath(const std::string& p,
if(root.size() == 1) if(root.size() == 1)
{ {
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
if(const char* userp = getenv("USERPROFILE")) if (!SystemTools::GetEnv("USERPROFILE", homedir))
{
homedir = userp;
}
else
#endif #endif
if(const char* h = getenv("HOME")) SystemTools::GetEnv("HOME", homedir);
{
homedir = h;
}
} }
#ifdef HAVE_GETPWNAM #ifdef HAVE_GETPWNAM
else if(passwd* pw = getpwnam(root.c_str()+1)) else if(passwd* pw = getpwnam(root.c_str()+1))
@ -4899,7 +4890,7 @@ int SystemTools::GetTerminalWidth()
int width = -1; int width = -1;
#ifdef HAVE_TTY_INFO #ifdef HAVE_TTY_INFO
struct winsize ws; struct winsize ws;
char *columns; /* Unix98 environment variable */ std::string columns; /* Unix98 environment variable */
if(ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>0 && ws.ws_row>0) if(ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>0 && ws.ws_row>0)
{ {
width = ws.ws_col; width = ws.ws_col;
@ -4908,12 +4899,11 @@ int SystemTools::GetTerminalWidth()
{ {
width = -1; width = -1;
} }
columns = getenv("COLUMNS"); if(SystemTools::GetEnv("COLUMNS", columns) && !columns.empty())
if(columns && *columns)
{ {
long t; long t;
char *endptr; char *endptr;
t = strtol(columns, &endptr, 0); t = strtol(columns.c_str(), &endptr, 0);
if(endptr && !*endptr && (t>0) && (t<1000)) if(endptr && !*endptr && (t>0) && (t<1000))
{ {
width = static_cast<int>(t); width = static_cast<int>(t);
@ -5525,7 +5515,8 @@ void SystemTools::ClassInitialize()
// If the current working directory is a logical path then keep the // If the current working directory is a logical path then keep the
// logical name. // logical name.
if(const char* pwd = getenv("PWD")) std::string pwd_str;
if(SystemTools::GetEnv("PWD", pwd_str))
{ {
char buf[2048]; char buf[2048];
if(const char* cwd = Getcwd(buf, 2048)) if(const char* cwd = Getcwd(buf, 2048))
@ -5537,10 +5528,9 @@ void SystemTools::ClassInitialize()
std::string pwd_changed; std::string pwd_changed;
// Test progressively shorter logical-to-physical mappings. // Test progressively shorter logical-to-physical mappings.
std::string pwd_str = pwd;
std::string cwd_str = cwd; std::string cwd_str = cwd;
std::string pwd_path; std::string pwd_path;
Realpath(pwd, pwd_path); Realpath(pwd_str.c_str(), pwd_path);
while(cwd_str == pwd_path && cwd_str != pwd_str) while(cwd_str == pwd_path && cwd_str != pwd_str)
{ {
// The current pair of paths is a working logical mapping. // The current pair of paths is a working logical mapping.
@ -5596,8 +5586,8 @@ static int SystemToolsDebugReport(int, char* message, int*)
void SystemTools::EnableMSVCDebugHook() void SystemTools::EnableMSVCDebugHook()
{ {
if (getenv("DART_TEST_FROM_DART") || if (SystemTools::HasEnv("DART_TEST_FROM_DART") ||
getenv("DASHBOARD_TEST_FROM_CTEST")) SystemTools::HasEnv("DASHBOARD_TEST_FROM_CTEST"))
{ {
_CrtSetReportHook(SystemToolsDebugReport); _CrtSetReportHook(SystemToolsDebugReport);
} }

View File

@ -848,9 +848,9 @@ static bool CheckPutEnv(const std::string& env, const char* name, const char* va
<< "\") failed!" << std::endl; << "\") failed!" << std::endl;
return false; return false;
} }
const char* v = kwsys::SystemTools::GetEnv(name); std::string v = "(null)";
v = v? v : "(null)"; kwsys::SystemTools::GetEnv(name, v);
if(strcmp(v, value) != 0) if(v != value)
{ {
std::cerr << "GetEnv(\"" << name << "\") returned \"" std::cerr << "GetEnv(\"" << name << "\") returned \""
<< v << "\", not \"" << value << "\"!" << std::endl; << v << "\", not \"" << value << "\"!" << std::endl;
@ -867,7 +867,8 @@ static bool CheckUnPutEnv(const char* env, const char* name)
<< std::endl; << std::endl;
return false; return false;
} }
if(const char* v = kwsys::SystemTools::GetEnv(name)) std::string v;
if(kwsys::SystemTools::GetEnv(name, v))
{ {
std::cerr << "GetEnv(\"" << name << "\") returned \"" std::cerr << "GetEnv(\"" << name << "\") returned \""
<< v << "\", not (null)!" << std::endl; << v << "\", not (null)!" << std::endl;