diff options
Diffstat (limited to 'backends/fs/posix/posix-fs.cpp')
-rw-r--r-- | backends/fs/posix/posix-fs.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 65e8c6bd86..0ea131b3f9 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -27,6 +27,7 @@ #endif #include <sys/stat.h> #include <dirent.h> +#include <stdio.h> /* * Implementation of the ScummVM file system API based on POSIX. @@ -119,9 +120,33 @@ FSList *POSIXFilesystemNode::listDir() const { return myList; } +const char *lastPathComponent(const ScummVM::String &str) { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; + + while (cur > start && *cur != '/') { + --cur; + } + + return cur+1; +} + FilesystemNode *POSIXFilesystemNode::parent() const { - // TODO !!! - return 0; + + POSIXFilesystemNode *p = new POSIXFilesystemNode(); + + // Root node is its own parent. Still we can't just return this + // as the GUI code will call delete on the old node. + if (_path != "/") { + const char *start = _path.c_str(); + const char *end = lastPathComponent(_path); + + p->_path = String(start, end - start); + p->_isValid = true; + p->_isDirectory = true; + p->_displayName = lastPathComponent(p->_path); + } + return p; } #endif // defined(UNIX) |