Daniele Bartolini 12 лет назад
Родитель
Сommit
5825ca86e0
2 измененных файлов с 19 добавлено и 13 удалено
  1. 9 5
      src/Filesystem.cpp
  2. 10 8
      src/Filesystem.h

+ 9 - 5
src/Filesystem.cpp

@@ -32,9 +32,13 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-Filesystem::Filesystem(const char* root_path) :
-	m_root_path(root_path)
+Filesystem::Filesystem(const char* root_path)
 {
+	assert(root_path != NULL);
+	assert(os::is_absolute_path(root_path));
+
+	string::strncpy(m_root_path, root_path, os::MAX_PATH_LENGTH);
+
 	Log::I("Root path : %s", m_root_path);
 }
 
@@ -52,7 +56,7 @@ const char* Filesystem::root_path() const
 //-----------------------------------------------------------------------------
 const char* Filesystem::build_os_path(const char* base_path, const char* relative_path)
 {
-	static char os_path[1024];
+	static char os_path[os::MAX_PATH_LENGTH];
 
 	size_t i = 0;
 
@@ -92,8 +96,8 @@ bool Filesystem::get_info(const char* base_path, const char* relative_path, File
 
 	const char* os_path = build_os_path(base_path, relative_path);
 	
-	string::strncpy(info.os_path, os_path, 512);
-	string::strncpy(info.relative_path, relative_path, 512);
+	string::strncpy(info.os_path, os_path, os::MAX_PATH_LENGTH);
+	string::strncpy(info.relative_path, relative_path, os::MAX_PATH_LENGTH);
 
 	if (os::is_reg(os_path))
 	{

+ 10 - 8
src/Filesystem.h

@@ -27,6 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "String.h"
 #include "Stream.h"
+#include "OS.h"
 
 namespace crown
 {
@@ -35,17 +36,17 @@ struct FilesystemEntry
 {
 	enum Type
 	{
-		DIRECTORY = 0,				///< The entry is a directory
-		FILE,						///< The entry is a file
-		MEMORY,						///< The entry is a memory file (i.e. does not exist on the disk)
-		UNKNOWN						///< The entry type is unknown
+		DIRECTORY = 0,		///< The entry is a directory
+		FILE,				///< The entry is a file
+		MEMORY,				///< The entry is a memory file (i.e. does not exist on the disk)
+		UNKNOWN				///< The entry type is unknown
 	};
 
 	FilesystemEntry() : type(UNKNOWN) {}
 
-	Type			type;				///< Type of the entry
-	char			os_path[512];		///< OS-specific path (use only for debug)
-	char			relative_path[512];	///< Relative path of the entry
+	Type			type;								///< Type of the entry
+	char			os_path[os::MAX_PATH_LENGTH];		///< OS-specific path (use only for debug)
+	char			relative_path[os::MAX_PATH_LENGTH];	///< Relative path of the entry
 };
 
 /// Filesystem.
@@ -100,6 +101,7 @@ class Filesystem
 {
 public:
 
+						/// The @root_path must be absolute.
 						Filesystem(const char* root_path);
 						~Filesystem();
 
@@ -136,7 +138,7 @@ private:
 	
 private:
 
-	const char*			m_root_path;
+	char				m_root_path[os::MAX_PATH_LENGTH];
 
 						// Disable copying
 						Filesystem(const Filesystem&);