Add FileOps method to get the canonical path for a file and the Unix implementation.

This commit is contained in:
Robert Knight 2011-08-21 21:50:20 +01:00
parent b49332eaab
commit 55ebb233cb
2 changed files with 21 additions and 0 deletions

View file

@ -233,3 +233,23 @@ void FileOps::rmdirRecursive(const char* path) throw (IOException)
rmdir(path);
}
std::string FileOps::canonicalPath(const char* path)
{
#ifdef PLATFORM_UNIX
// on Linux and Mac OS 10.6, realpath() can allocate the required
// amount of memory automatically, however Mac OS 10.5 does not support
// this, so we used a fixed-sized buffer on all platforms
char canonicalPathBuffer[PATH_MAX+1];
if (realpath(path,canonicalPathBuffer) != 0)
{
return std::string(canonicalPathBuffer);
}
else
{
throw IOException("Error reading canonical path for " + std::string(path));
}
#else
throw IOException("Not implemented");
#endif
}

View file

@ -36,5 +36,6 @@ class FileOps
static void touch(const char* path) throw (IOException);
static std::string dirname(const char* path);
static void rmdirRecursive(const char* dir) throw (IOException);
static std::string canonicalPath(const char* path);
};