ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

chroot-fs.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #if defined(POSIX)
00024 
00025 // Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
00026 // Also with clock() in sys/time.h in some Mac OS X SDKs.
00027 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
00028 #define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
00029 #define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
00030 #define FORBIDDEN_SYMBOL_EXCEPTION_getenv
00031 #define FORBIDDEN_SYMBOL_EXCEPTION_exit     //Needed for IRIX's unistd.h
00032 #define FORBIDDEN_SYMBOL_EXCEPTION_random
00033 #define FORBIDDEN_SYMBOL_EXCEPTION_srandom
00034 
00035 #include "backends/fs/chroot/chroot-fs.h"
00036 
00037 ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFilesystemNode *node) {
00038     _root = Common::normalizePath(root, '/');
00039     _realNode = node;
00040 }
00041 
00042 ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
00043     _root = Common::normalizePath(root, '/');
00044     _realNode = new POSIXFilesystemNode(addPathComponent(root, path));
00045 }
00046 
00047 ChRootFilesystemNode::~ChRootFilesystemNode() {
00048     delete _realNode;
00049 }
00050 
00051 bool ChRootFilesystemNode::exists() const {
00052     return _realNode->exists();
00053 }
00054 
00055 Common::String ChRootFilesystemNode::getDisplayName() const {
00056     return getName();
00057 }
00058 
00059 Common::String ChRootFilesystemNode::getName() const {
00060     return _realNode->AbstractFSNode::getDisplayName();
00061 }
00062 
00063 Common::String ChRootFilesystemNode::getPath() const {
00064     Common::String path = _realNode->getPath();
00065     if (path.size() > _root.size()) {
00066         return Common::String(path.c_str() + _root.size());
00067     }
00068     return Common::String("/");
00069 }
00070 
00071 bool ChRootFilesystemNode::isDirectory() const {
00072     return _realNode->isDirectory();
00073 }
00074 
00075 bool ChRootFilesystemNode::isReadable() const {
00076     return _realNode->isReadable();
00077 }
00078 
00079 bool ChRootFilesystemNode::isWritable() const {
00080     return _realNode->isWritable();
00081 }
00082 
00083 AbstractFSNode *ChRootFilesystemNode::getChild(const Common::String &n) const {
00084     return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getChild(n));
00085 }
00086 
00087 bool ChRootFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
00088     AbstractFSList tmp;
00089     if (!_realNode->getChildren(tmp, mode, hidden)) {
00090         return false;
00091     }
00092 
00093     for (AbstractFSList::iterator i=tmp.begin(); i!=tmp.end(); ++i) {
00094         list.push_back(new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) *i));
00095     }
00096 
00097     return true;
00098 }
00099 
00100 AbstractFSNode *ChRootFilesystemNode::getParent() const {
00101     if (getPath() == "/") return 0;
00102     return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *)_realNode->getParent());
00103 }
00104 
00105 Common::SeekableReadStream *ChRootFilesystemNode::createReadStream() {
00106     return _realNode->createReadStream();
00107 }
00108 
00109 Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
00110     return _realNode->createWriteStream();
00111 }
00112 
00113 bool ChRootFilesystemNode::create(bool isDirectoryFlag) {
00114     error("Not supported");
00115     return false;
00116 }
00117 
00118 Common::String ChRootFilesystemNode::addPathComponent(const Common::String &path, const Common::String &component) {
00119     const char sep = '/';
00120     if (path.lastChar() == sep && component.firstChar() == sep) {
00121         return Common::String::format("%s%s", path.c_str(), component.c_str() + 1);
00122     }
00123 
00124     if (path.lastChar() == sep || component.firstChar() == sep) {
00125         return Common::String::format("%s%s", path.c_str(), component.c_str());
00126     }
00127 
00128     return Common::String::format("%s%c%s", path.c_str(), sep, component.c_str());
00129 }
00130 
00131 #endif


Generated on Sat Mar 16 2019 05:01:21 for ResidualVM by doxygen 1.7.1
curved edge   curved edge