#199: ADd method to return the absolute (real) path.

This commit is contained in:
ThorstenB 2012-01-12 21:44:15 +01:00
parent 7ee2633164
commit cee8c5b5c7
2 changed files with 24 additions and 5 deletions

View File

@ -483,3 +483,16 @@ bool SGPath::rename(const SGPath& newName)
return true;
}
std::string SGPath::realpath() const
{
#ifdef _WIN32
// Not implemented for Windows yet. Return original path instead.
return path;
#else
char* buf = ::realpath(path.c_str(), NULL);
std::string p(buf);
free(buf);
return p;
#endif
}

View File

@ -111,6 +111,12 @@ public:
*/
void concat( const std::string& p );
/**
* Returns a string with the absolute pathname that names the same file, whose
* resolution does not involve '.', '..', or symbolic links.
*/
std::string realpath() const;
/**
* Get the file part of the path (everything after the last path sep)
* @return file string