[Scummvm-cvs-logs] CVS: scummvm/backends/fs/posix posix-fs.cpp,1.17,1.18

Max Horn fingolfin at users.sourceforge.net
Sat Jan 31 17:34:12 CET 2004


Update of /cvsroot/scummvm/scummvm/backends/fs/posix
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11078/posix

Modified Files:
	posix-fs.cpp 
Log Message:
Added FilesystemNode::getNodeForPath, but right now only for Mac OS X

Index: posix-fs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/fs/posix/posix-fs.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- posix-fs.cpp	6 Jan 2004 12:45:26 -0000	1.17
+++ posix-fs.cpp	1 Feb 2004 01:31:50 -0000	1.18
@@ -83,6 +83,12 @@
 	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 @@
 	_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 *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 @@
 		POSIXFilesystemNode entry;
 		entry._displayName = dp->d_name;
 		entry._path = _path;
+		if (entry._path.lastChar() != '/')
+			entry._path += '/';
 		entry._path += dp->d_name;
 
 #ifdef __DC__





More information about the Scummvm-git-logs mailing list