mirror of https://github.com/stella-emu/stella.git
FilesystemNode class how properly deals with relative files
in Linux/OSX; still TODO is add support for Windows. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2507 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
b725bf8fd6
commit
f60524770a
|
@ -141,8 +141,8 @@ POSIXFilesystemNode::POSIXFilesystemNode()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
||||
{
|
||||
// Expand '~/' and './' to the value of the HOME env variable
|
||||
if ( p.length() >= 2 && (p[0] == '~' || p[0] == '.') && p[1] == '/')
|
||||
// Expand '~/' to the HOME environment variable
|
||||
if (p.length() >= 2 && p[0] == '~' && p[1] == '/')
|
||||
{
|
||||
const char *home = getenv("HOME");
|
||||
#ifdef MAXPATHLEN
|
||||
|
@ -157,6 +157,28 @@ POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
|||
_path += p.c_str() + 1;
|
||||
}
|
||||
}
|
||||
// Expand './' to the current working directory,
|
||||
// likewise if the path is relative (doesn't start with '/')
|
||||
else if ((p.length() >= 2 && p[0] == '.' && p[1] == '/') ||
|
||||
(p.length() >= 1 && p[0] != '/'))
|
||||
{
|
||||
char* cwd = get_current_dir_name();
|
||||
#ifdef MAXPATHLEN
|
||||
if (cwd != NULL && strlen(cwd) < MAXPATHLEN)
|
||||
#else // No MAXPATHLEN, as happens on Hurd
|
||||
if (cwd != NULL)
|
||||
#endif
|
||||
{
|
||||
_path = cwd;
|
||||
if(p[0] == '.')
|
||||
// Skip over the tilde/dot. We know that p contains at least
|
||||
// two chars, so this is safe:
|
||||
_path = _path + (p.c_str() + 1);
|
||||
else
|
||||
_path = _path + '/' + p;
|
||||
}
|
||||
free(cwd);
|
||||
}
|
||||
else
|
||||
_path = p;
|
||||
|
||||
|
|
|
@ -236,17 +236,24 @@ WindowsFilesystemNode::WindowsFilesystemNode()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
WindowsFilesystemNode::WindowsFilesystemNode(const string& p)
|
||||
{
|
||||
// Expand '~\' and '.\' to the users 'home' directory
|
||||
if ( p.length() >= 2 && (p[0] == '~' || p[0] == '.') && p[1] == '\\')
|
||||
// Expand '~\' to the users 'home' directory
|
||||
if (p.length() >= 2 && p[0] == '~' && p[1] == '\\')
|
||||
{
|
||||
_path = myHomeFinder.getHomePath();
|
||||
// Skip over the tilde/dot. We know that p contains at least
|
||||
// two chars, so this is safe:
|
||||
_path += p.c_str() + 1;
|
||||
}
|
||||
// Expand '.\' to the current working directory,
|
||||
// likewise if the path is relative (second character not a colon)
|
||||
else if ((p.length() >= 2 && ((p[0] == '.' && p[1] == '\\') ||
|
||||
p[1] != ':'))
|
||||
{
|
||||
// TODO - implement this
|
||||
_path = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(p.size() > 0);
|
||||
_path = p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue