summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorClinton Stimpson <clinton@elemtech.com>2007-01-16 14:37:33 -0500
committerClinton Stimpson <clinton@elemtech.com>2007-01-16 14:37:33 -0500
commite264771122c01176b2a31cf98a9343c091599216 (patch)
treeaaa74ebe33a9839b650d0f50b502d4ff79a8e1a9 /Source
parent8388640c03a9b34e98a0e19deef5da28979aab83 (diff)
downloadcmake-e264771122c01176b2a31cf98a9343c091599216.tar.gz
ENH: Add support for "~otheruser/"
Diffstat (limited to 'Source')
-rw-r--r--Source/kwsys/SystemTools.cxx60
1 files changed, 51 insertions, 9 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 5ffd032d71..b6fabc74dc 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -55,6 +55,7 @@
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <pwd.h>
#include <termios.h>
#include <signal.h> /* sigprocmask */
#endif
@@ -1367,7 +1368,7 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
{
// if there is a tilda ~ then replace it with HOME
pathCString = path.c_str();
- if(*pathCString == '~')
+ if(pathCString[0] == '~' && (pathCString[1] == '/' || pathCString[1] == '\0'))
{
const char* homeEnv = SystemTools::GetEnv("HOME");
if (homeEnv)
@@ -1375,6 +1376,18 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
path.replace(0,1,homeEnv);
}
}
+#if !defined(_WIN32)
+ else if(pathCString[0] == '~')
+ {
+ kwsys_stl::string::size_type idx = path.find_first_of("/\0");
+ kwsys_stl::string user = path.substr(1, idx-1);
+ passwd* pw = getpwnam(user.c_str());
+ if(pw)
+ {
+ path.replace(0, idx, pw->pw_dir);
+ }
+ }
+#endif
// remove trailing slash if the path is more than
// a single /
pathCString = path.c_str();
@@ -2829,19 +2842,42 @@ void SystemTools::SplitPath(const char* p,
components.push_back(root);
c += 2;
}
+#if !defined(_WIN32)
else if(c[0] == '~')
{
- const char* homepath = getenv("HOME");
- if(homepath)
+ int numChars = 1;
+ while(c[numChars] && c[numChars] != '/')
{
- kwsys_stl::vector<kwsys_stl::string> home_components;
- SystemTools::SplitPath(homepath, home_components);
- components.insert(components.end(),
- home_components.begin(),
- home_components.end());
+ numChars++;
}
- c += 1;
+ const char* homedir;
+ if(numChars == 1)
+ {
+ homedir = getenv("HOME");
+ }
+ else
+ {
+ char user[PATH_MAX];
+ strncpy(user, c+1, numChars-1);
+ user[numChars] = '\0';
+ passwd* pw = getpwnam(user);
+ if(p)
+ {
+ homedir = pw->pw_dir;
+ }
+ else
+ {
+ homedir = "";
+ }
+ }
+ kwsys_stl::vector<kwsys_stl::string> home_components;
+ SystemTools::SplitPath(homedir, home_components);
+ components.insert(components.end(),
+ home_components.begin(),
+ home_components.end());
+ c += numChars;
}
+#endif
else
{
// Relative path.
@@ -3314,6 +3350,12 @@ bool SystemTools::FileIsFullPath(const char* in_name)
return false;
}
#endif
+#if !defined(_WIN32)
+ if(name[0] == '~')
+ {
+ return true;
+ }
+#endif
// On UNIX, the name must begin in a '/'.
// On Windows, if the name begins in a '/', then it is a full
// network path.