ENH: Added kwsys SystemTools::CreateSymlink and SystemTools::ReadSymlink.
This commit is contained in:
parent
558dbc84ad
commit
e01cdf2065
|
@ -1376,20 +1376,6 @@ bool cmSystemTools::StringEndsWith(const char* str1, const char* str2)
|
||||||
return !strncmp(str1 + (strlen(str1)-strlen(str2)), str2, strlen(str2));
|
return !strncmp(str1 + (strlen(str1)-strlen(str2)), str2, strlen(str2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
||||||
bool cmSystemTools::CreateSymlink(const char*, const char*)
|
|
||||||
{
|
|
||||||
// Should we create a copy here?
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
bool cmSystemTools::CreateSymlink(const char* origName, const char* newName)
|
|
||||||
{
|
|
||||||
return (symlink(origName, newName) >= 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// compute the relative path from here to there
|
// compute the relative path from here to there
|
||||||
std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
||||||
{
|
{
|
||||||
|
|
|
@ -297,7 +297,6 @@ public:
|
||||||
static std::string ConvertToRunCommandPath(const char* path);
|
static std::string ConvertToRunCommandPath(const char* path);
|
||||||
//! Check if the first string ends with the second one.
|
//! Check if the first string ends with the second one.
|
||||||
static bool StringEndsWith(const char* str1, const char* str2);
|
static bool StringEndsWith(const char* str1, const char* str2);
|
||||||
static bool CreateSymlink(const char* origName, const char* newName);
|
|
||||||
|
|
||||||
/** compute the relative path from local to remote. local must
|
/** compute the relative path from local to remote. local must
|
||||||
be a directory. remote can be a file or a directory.
|
be a directory. remote can be a file or a directory.
|
||||||
|
|
|
@ -2356,6 +2356,44 @@ bool SystemTools::FileIsSymlink(const char* name)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
bool SystemTools::CreateSymlink(const char*, const char*)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
bool SystemTools::CreateSymlink(const char* origName, const char* newName)
|
||||||
|
{
|
||||||
|
return symlink(origName, newName) >= 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
bool SystemTools::ReadSymlink(const char*, kwsys_stl::string&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
bool SystemTools::ReadSymlink(const char* newName,
|
||||||
|
kwsys_stl::string& origName)
|
||||||
|
{
|
||||||
|
char buf[KWSYS_SYSTEMTOOLS_MAXPATH+1];
|
||||||
|
int count =
|
||||||
|
static_cast<int>(readlink(newName, buf, KWSYS_SYSTEMTOOLS_MAXPATH));
|
||||||
|
if(count >= 0)
|
||||||
|
{
|
||||||
|
// Add null-terminator.
|
||||||
|
buf[count] = 0;
|
||||||
|
origName = buf;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int SystemTools::ChangeDirectory(const char *dir)
|
int SystemTools::ChangeDirectory(const char *dir)
|
||||||
{
|
{
|
||||||
return Chdir(dir);
|
return Chdir(dir);
|
||||||
|
|
|
@ -588,6 +588,18 @@ public:
|
||||||
unsigned long length = 256,
|
unsigned long length = 256,
|
||||||
double percent_bin = 0.05);
|
double percent_bin = 0.05);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a symbolic link if the platform supports it. Returns whether
|
||||||
|
* creation succeded.
|
||||||
|
*/
|
||||||
|
static bool CreateSymlink(const char* origName, const char* newName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the contents of a symbolic link. Returns whether reading
|
||||||
|
* succeded.
|
||||||
|
*/
|
||||||
|
static bool ReadSymlink(const char* 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'.
|
||||||
* If 'filename' is a fully qualified filename, the basename of the file is
|
* If 'filename' is a fully qualified filename, the basename of the file is
|
||||||
|
|
Loading…
Reference in New Issue