diff options
author | Max Horn | 2004-02-01 01:31:50 +0000 |
---|---|---|
committer | Max Horn | 2004-02-01 01:31:50 +0000 |
commit | 28f8f4d0918db1fd71f80cc9b0b02bb04cda6e48 (patch) | |
tree | 3b7a4e0de562c0a5970911812754c6d3875c28f4 /backends/fs/posix | |
parent | 9fe1aaa9215e2ca540c859f2647629453a9f70d6 (diff) | |
download | scummvm-rg350-28f8f4d0918db1fd71f80cc9b0b02bb04cda6e48.tar.gz scummvm-rg350-28f8f4d0918db1fd71f80cc9b0b02bb04cda6e48.tar.bz2 scummvm-rg350-28f8f4d0918db1fd71f80cc9b0b02bb04cda6e48.zip |
Added FilesystemNode::getNodeForPath, but right now only for Mac OS X
svn-id: r12692
Diffstat (limited to 'backends/fs/posix')
-rw-r--r-- | backends/fs/posix/posix-fs.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index bb50142769..86c29910b5 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -83,6 +83,12 @@ FilesystemNode *FilesystemNode::getRoot() { return new POSIXFilesystemNode(); } +#ifdef MACOSX +FilesystemNode *FilesystemNode::getNodeForPath(const String &path) { + return new POSIXFilesystemNode(path); +} +#endif + POSIXFilesystemNode::POSIXFilesystemNode() { #ifndef __DC__ char buf[MAXPATHLEN]; @@ -99,16 +105,33 @@ POSIXFilesystemNode::POSIXFilesystemNode() { _isDirectory = true; } -/* POSIXFilesystemNode::POSIXFilesystemNode(const String &p) { - // TODO - extract last component from path - _displayName = p; - // TODO - check whether it is a directory, and whether the file actually exists + int len = 0, offset = p.size(); + struct stat st; + + assert(offset > 0); + + _path = p; + + // Extract last component from path + const char *str = p.c_str(); + while (offset > 0 && str[offset-1] == '/') + offset--; + while (offset > 0 && str[offset-1] != '/') { + len++; + offset--; + } + _displayName = String(str + offset, len); + + // Check whether it is a directory, and whether the file actually exists +#ifdef __DC__ _isValid = true; _isDirectory = true; - _path = p; +#else + _isValid = (0 == stat(_path.c_str(), &st)); + _isDirectory = S_ISDIR(st.st_mode); +#endif } -*/ POSIXFilesystemNode::POSIXFilesystemNode(const POSIXFilesystemNode *node) { _displayName = node->_displayName; @@ -126,7 +149,7 @@ FSList *POSIXFilesystemNode::listDir(ListMode mode) const { FSList *myList = new FSList(); if (dirp == NULL) return myList; - + // ... loop over dir entries using readdir while ((dp = readdir(dirp)) != NULL) { // Skip 'invisible' files @@ -136,6 +159,8 @@ FSList *POSIXFilesystemNode::listDir(ListMode mode) const { POSIXFilesystemNode entry; entry._displayName = dp->d_name; entry._path = _path; + if (entry._path.lastChar() != '/') + entry._path += '/'; entry._path += dp->d_name; #ifdef __DC__ |