Commit 3c066bd4 authored by hybrid's avatar hybrid

Changed file position data type to long in order to support large files on...

Changed file position data type to long in order to support large files on 64bit systems. Also added some constification and signedness changes to file classes.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@953 dfc29bdd-3216-0410-991c-e03cc46cb475
parent fa1534ee
......@@ -23,7 +23,7 @@ public:
//! Returns the amount of files in the filelist.
//! \return
//! Returns the amount of files and directories in the file list.
virtual s32 getFileCount() = 0;
virtual u32 getFileCount() const = 0;
//! Gets the name of a file in the list, based on an index.
//! The path is not included in this name. Use getFullFileName for this.
......@@ -31,14 +31,14 @@ public:
//! be returned. The index has to be smaller than the amount getFileCount() returns.
//! \return
//! Returns the file name of the file. Returns 0, if an error occured.
virtual const c8* getFileName(s32 index) = 0;
virtual const c8* getFileName(u32 index) const = 0;
//! Gets the full name of a file in the list, path included, based on an index.
//! \param index is the zero based index of the file which name should
//! be returned. The index has to be smaller than the amount getFileCount() returns.
//! \return
//! Returns the file name of the file. Returns 0, if an error occured.
virtual const c8* getFullFileName(s32 index) = 0;
virtual const c8* getFullFileName(u32 index) = 0;
//! Returns of the file is a directory
//! \param
......@@ -47,7 +47,7 @@ public:
//! \return
//! Returns true, if the file is a directory, and false, if it is not.
//! If an error occurs, the result is undefined.
virtual bool isDirectory(s32 index) = 0;
virtual bool isDirectory(u32 index) const = 0;
};
} // end namespace irr
......
......@@ -31,27 +31,27 @@ namespace io
//! changed relative to current position. Otherwise the position is changed
//! from beginning of file.
//! \return Returns true if successful, otherwise false.
virtual bool seek(s32 finalPos, bool relativeMovement = false) = 0;
virtual bool seek(long finalPos, bool relativeMovement = false) = 0;
//! Returns size of file.
//! \return Returns the size of the file in bytes.
virtual s32 getSize() = 0;
virtual long getSize() = 0;
//! Returns the current position in the file.
//! \return Returns the current position in the file in bytes.
virtual s32 getPos() = 0;
virtual long getPos() = 0;
//! Returns name of file.
//! \return Returns the file name as zero terminated character string.
virtual const c8* getFileName() = 0;
virtual const c8* getFileName() const = 0;
};
//! Internal function, please do not use.
IReadFile* createReadFile(const c8* fileName);
//! Internal function, please do not use.
IReadFile* createLimitReadFile(const c8* fileName, IReadFile* alreadyOpenedFile, s32 areaSize);
IReadFile* createLimitReadFile(const c8* fileName, IReadFile* alreadyOpenedFile, long areaSize);
//! Internal function, please do not use.
IReadFile* createMemoryReadFile(void* memory, s32 size, const c8* fileName, bool deleteMemoryWhenDropped);
IReadFile* createMemoryReadFile(void* memory, long size, const c8* fileName, bool deleteMemoryWhenDropped);
} // end namespace io
} // end namespace irr
......
......@@ -21,9 +21,9 @@ namespace io
//! Reads an amount of bytes from the file.
//! \param buffer: Pointer to buffer of bytes to write.
//! \param sizeToWrite: Amount of bytes to wrtie to the file.
//! \param sizeToWrite: Amount of bytes to write to the file.
//! \return Returns how much bytes were written.
virtual s32 write(const void* buffer, s32 sizeToWrite) = 0;
virtual s32 write(const void* buffer, u32 sizeToWrite) = 0;
//! Changes position in file, returns true if successful.
//! \param finalPos: Destination position in the file.
......@@ -31,15 +31,15 @@ namespace io
//! changed relative to current position. Otherwise the position is changed
//! from begin of file.
//! \return Returns true if successful, otherwise false.
virtual bool seek(s32 finalPos, bool relativeMovement = false) = 0;
virtual bool seek(long finalPos, bool relativeMovement = false) = 0;
//! Returns the current position in the file.
//! \return Returns the current position in the file in bytes.
virtual s32 getPos() = 0;
virtual long getPos() = 0;
//! Returns name of file.
//! \return Returns the file name as zero terminated character string.
virtual const c8* getFileName() = 0;
virtual const c8* getFileName() const = 0;
};
//! Internal function, please do not use.
......
......@@ -31,7 +31,6 @@ namespace io
CFileList::CFileList()
{
#ifdef _DEBUG
setDebugName("CFileList");
#endif
......@@ -131,30 +130,25 @@ CFileList::CFileList()
}
CFileList::~CFileList()
{
}
s32 CFileList::getFileCount()
u32 CFileList::getFileCount() const
{
return Files.size();
}
const c8* CFileList::getFileName(s32 index)
const c8* CFileList::getFileName(u32 index) const
{
if (index < 0 || index > (s32)Files.size())
if (index < Files.size())
return Files[index].Name.c_str();
else
return 0;
return Files[index].Name.c_str();
}
//! Gets the full name of a file in the list, path included, based on an index.
const c8* CFileList::getFullFileName(s32 index)
const c8* CFileList::getFullFileName(u32 index)
{
if (index < 0 || index > (s32)Files.size())
if (index >= Files.size())
return 0;
if (Files[index].FullName.size() < Files[index].Name.size())
......@@ -172,13 +166,16 @@ const c8* CFileList::getFullFileName(s32 index)
}
bool CFileList::isDirectory(s32 index)
bool CFileList::isDirectory(u32 index) const
{
if (index < 0 || index > (s32)Files.size())
return false;
bool ret;
if (index >= Files.size())
ret = false;
else
ret = Files[index].isDirectory;
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return Files[index].isDirectory;
return ret;
}
} // end namespace irr
......
......@@ -25,23 +25,20 @@ public:
//! constructor
CFileList();
//! destructor
virtual ~CFileList();
//! Returns the amount of files in the filelist.
//! \return
//! Returns the amount of files and directories in the file list.
virtual s32 getFileCount();
virtual u32 getFileCount() const;
//! Gets the name of a file in the list, based on an index.
//! \param index is the zero based index of the file which name should
//! be returned. The index has to be smaller than the amount getFileCount() returns.
//! \return
//! Returns the file name of the file. Returns 0, if an error occured.
virtual const c8* getFileName(s32 index);
virtual const c8* getFileName(u32 index) const;
//! Gets the full name of a file in the list, path included, based on an index.
virtual const c8* getFullFileName(s32 index);
virtual const c8* getFullFileName(u32 index);
//! Returns of the file is a directory
//! \param index is the zero based index of the file which name should
......@@ -49,7 +46,7 @@ public:
//! \return
//! Returns true, if the file is a directory, and false, if it is not.
//! If an error occurs, the result is undefined.
virtual bool isDirectory(s32 index);
virtual bool isDirectory(u32 index) const;
private:
......@@ -57,7 +54,7 @@ private:
{
core::stringc Name;
core::stringc FullName;
s32 Size;
long Size;
bool isDirectory;
bool operator <(const struct FileEntry& other) const
......
......@@ -11,7 +11,7 @@ namespace io
{
CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, s32 areaSize, const c8* name)
CLimitReadFile::CLimitReadFile(IReadFile* alreadyOpenedFile, long areaSize, const c8* name)
: Filename(name), AreaSize(areaSize), AreaStart(0), AreaEnd(0), File(alreadyOpenedFile)
{
#ifdef _DEBUG
......@@ -47,12 +47,12 @@ CLimitReadFile::~CLimitReadFile()
//! returns how much was read
s32 CLimitReadFile::read(void* buffer, u32 sizeToRead)
{
s32 pos = File->getPos();
long pos = File->getPos();
if (pos >= AreaEnd)
return 0;
if (pos + (s32)sizeToRead >= AreaEnd)
if (pos + sizeToRead >= AreaEnd)
sizeToRead = AreaEnd - pos;
return File->read(buffer, sizeToRead);
......@@ -63,9 +63,9 @@ s32 CLimitReadFile::read(void* buffer, u32 sizeToRead)
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
bool CLimitReadFile::seek(s32 finalPos, bool relativeMovement)
bool CLimitReadFile::seek(long finalPos, bool relativeMovement)
{
s32 pos = File->getPos();
long pos = File->getPos();
if (relativeMovement)
{
......@@ -75,7 +75,7 @@ bool CLimitReadFile::seek(s32 finalPos, bool relativeMovement)
else
{
finalPos += AreaStart;
if ((s32)finalPos > AreaEnd)
if (finalPos > AreaEnd)
return false;
}
......@@ -83,9 +83,8 @@ bool CLimitReadFile::seek(s32 finalPos, bool relativeMovement)
}
//! returns size of file
s32 CLimitReadFile::getSize()
long CLimitReadFile::getSize()
{
return AreaSize;
}
......@@ -93,7 +92,7 @@ s32 CLimitReadFile::getSize()
//! returns where in the file we are.
s32 CLimitReadFile::getPos()
long CLimitReadFile::getPos()
{
return File->getPos() - AreaStart;
}
......@@ -101,13 +100,13 @@ s32 CLimitReadFile::getPos()
//! returns name of file
const c8* CLimitReadFile::getFileName()
const c8* CLimitReadFile::getFileName() const
{
return Filename.c_str();
}
IReadFile* createLimitReadFile(const c8* fileName, IReadFile* alreadyOpenedFile, s32 areaSize)
IReadFile* createLimitReadFile(const c8* fileName, IReadFile* alreadyOpenedFile, long areaSize)
{
return new CLimitReadFile(alreadyOpenedFile, areaSize, fileName);
}
......@@ -115,3 +114,4 @@ IReadFile* createLimitReadFile(const c8* fileName, IReadFile* alreadyOpenedFile,
} // end namespace io
} // end namespace irr
......@@ -25,7 +25,7 @@ namespace io
{
public:
CLimitReadFile(IReadFile* alreadyOpenedFile, s32 areaSize, const c8* name);
CLimitReadFile(IReadFile* alreadyOpenedFile, long areaSize, const c8* name);
virtual ~CLimitReadFile();
......@@ -35,25 +35,25 @@ namespace io
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
virtual bool seek(s32 finalPos, bool relativeMovement = false);
virtual bool seek(long finalPos, bool relativeMovement = false);
//! returns size of file
virtual s32 getSize();
virtual long getSize();
//! returns where in the file we are.
virtual s32 getPos();
virtual long getPos();
//! returns name of file
virtual const c8* getFileName();
virtual const c8* getFileName() const;
private:
void init();
core::stringc Filename;
s32 AreaSize;
s32 AreaStart;
s32 AreaEnd;
long AreaSize;
long AreaStart;
long AreaEnd;
IReadFile* File;
};
......
......@@ -11,7 +11,7 @@ namespace io
{
CMemoryReadFile::CMemoryReadFile(void* memory, s32 len, const c8* fileName, bool d)
CMemoryReadFile::CMemoryReadFile(void* memory, long len, const c8* fileName, bool d)
: Buffer(memory), Len(len), Pos(0), deleteMemoryWhenDropped(d)
{
#ifdef _DEBUG
......@@ -34,27 +34,26 @@ CMemoryReadFile::~CMemoryReadFile()
//! returns how much was read
s32 CMemoryReadFile::read(void* buffer, u32 sizeToRead)
{
s32 amount = sizeToRead;
s32 amount = static_cast<s32>(sizeToRead);
if (Pos + amount > Len)
amount -= Pos + amount - Len;
if (amount < 0)
amount = 0;
if (amount <= 0)
return 0;
c8* p = (c8*)Buffer;
memcpy(buffer, p + Pos, amount);
Pos += static_cast<u32> ( amount );
Pos += amount;
return amount;
}
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
bool CMemoryReadFile::seek(s32 finalPos, bool relativeMovement)
bool CMemoryReadFile::seek(long finalPos, bool relativeMovement)
{
if (relativeMovement)
{
......@@ -65,10 +64,10 @@ bool CMemoryReadFile::seek(s32 finalPos, bool relativeMovement)
}
else
{
if ( (unsigned) finalPos > Len)
if (finalPos > Len)
return false;
Pos = finalPos;
Pos = finalPos;
}
return true;
......@@ -77,7 +76,7 @@ bool CMemoryReadFile::seek(s32 finalPos, bool relativeMovement)
//! returns size of file
s32 CMemoryReadFile::getSize()
long CMemoryReadFile::getSize()
{
return Len;
}
......@@ -85,7 +84,7 @@ s32 CMemoryReadFile::getSize()
//! returns where in the file we are.
s32 CMemoryReadFile::getPos()
long CMemoryReadFile::getPos()
{
return Pos;
}
......@@ -93,14 +92,14 @@ s32 CMemoryReadFile::getPos()
//! returns name of file
const c8* CMemoryReadFile::getFileName()
const c8* CMemoryReadFile::getFileName() const
{
return Filename.c_str();
}
IReadFile* createMemoryReadFile(void* memory, s32 size, const c8* fileName, bool deleteMemoryWhenDropped)
IReadFile* createMemoryReadFile(void* memory, long size, const c8* fileName, bool deleteMemoryWhenDropped)
{
CMemoryReadFile* file = new CMemoryReadFile(memory, size, fileName, deleteMemoryWhenDropped);
return file;
......
......@@ -21,7 +21,7 @@ namespace io
{
public:
CMemoryReadFile(void* memory, s32 len, const c8* fileName, bool deleteMemoryWhenDropped);
CMemoryReadFile(void* memory, long len, const c8* fileName, bool deleteMemoryWhenDropped);
virtual ~CMemoryReadFile();
......@@ -31,23 +31,23 @@ namespace io
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
virtual bool seek(s32 finalPos, bool relativeMovement = false);
virtual bool seek(long finalPos, bool relativeMovement = false);
//! returns size of file
virtual s32 getSize();
virtual long getSize();
//! returns where in the file we are.
virtual s32 getPos();
virtual long getPos();
//! returns name of file
virtual const c8* getFileName();
virtual const c8* getFileName() const;
private:
core::stringc Filename;
void *Buffer;
u32 Len;
u32 Pos;
long Len;
long Pos;
bool deleteMemoryWhenDropped;
};
......
......@@ -45,7 +45,7 @@ s32 CReadFile::read(void* buffer, u32 sizeToRead)
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
bool CReadFile::seek(s32 finalPos, bool relativeMovement)
bool CReadFile::seek(long finalPos, bool relativeMovement)
{
if (!isOpen())
return false;
......@@ -56,7 +56,7 @@ bool CReadFile::seek(s32 finalPos, bool relativeMovement)
//! returns size of file
s32 CReadFile::getSize()
long CReadFile::getSize()
{
return FileSize;
}
......@@ -64,7 +64,7 @@ s32 CReadFile::getSize()
//! returns where in the file we are.
s32 CReadFile::getPos()
long CReadFile::getPos()
{
return ftell(File);
}
......@@ -87,15 +87,14 @@ void CReadFile::openFile()
// get FileSize
fseek(File, 0, SEEK_END);
FileSize = ftell(File);
FileSize = getPos();
fseek(File, 0, SEEK_SET);
}
}
//! returns name of file
const c8* CReadFile::getFileName()
const c8* CReadFile::getFileName() const
{
return Filename.c_str();
}
......
......@@ -33,10 +33,10 @@ namespace io
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
virtual bool seek(s32 finalPos, bool relativeMovement = false);
virtual bool seek(long finalPos, bool relativeMovement = false);
//! returns size of file
virtual s32 getSize();
virtual long getSize();
//! returns if file is open
virtual bool isOpen() const
......@@ -45,10 +45,10 @@ namespace io
}
//! returns where in the file we are.
virtual s32 getPos();
virtual long getPos();
//! returns name of file
virtual const c8* getFileName();
virtual const c8* getFileName() const;
private:
......@@ -57,7 +57,7 @@ namespace io
core::stringc Filename;
FILE* File;
s32 FileSize;
long FileSize;
};
} // end namespace io
......
......@@ -41,7 +41,7 @@ inline bool CWriteFile::isOpen() const
//! returns how much was read
s32 CWriteFile::write(const void* buffer, s32 sizeToWrite)
s32 CWriteFile::write(const void* buffer, u32 sizeToWrite)
{
if (!isOpen())
return 0;
......@@ -54,7 +54,7 @@ s32 CWriteFile::write(const void* buffer, s32 sizeToWrite)
//! changes position in file, returns true if successful
//! if relativeMovement==true, the pos is changed relative to current pos,
//! otherwise from begin of file
bool CWriteFile::seek(s32 finalPos, bool relativeMovement)
bool CWriteFile::seek(long finalPos, bool relativeMovement)
{
if (!isOpen())
return false;
......@@ -65,7 +65,7 @@ bool CWriteFile::seek(s32 finalPos, bool relativeMovement)
//! returns where in the file we are.
s32 CWriteFile::getPos()
long CWriteFile::getPos()
{
return ftell(File);
}
......@@ -96,7 +96,7 @@ void CWriteFile::openFile(bool append)
//! returns name of file
const c8* CWriteFile::getFileName()
const c8* CWriteFile::getFileName() const
{
return Filename.c_str();
}
......
......@@ -28,16 +28,16 @@ namespace io
virtual ~CWriteFile();
//! Reads an amount of bytes from the file.
virtual s32 write(const void* buffer, s32 sizeToWrite);
virtual s32 write(const void* buffer, u32 sizeToWrite);
//! Changes position in file, returns true if successful.
virtual bool seek(s32 finalPos, bool relativeMovement = false);
virtual bool seek(long finalPos, bool relativeMovement = false);
//! Returns the current position in the file.
virtual s32 getPos();
virtual long getPos();
//! Returns name of file.
virtual const c8* getFileName();
virtual const c8* getFileName() const;
//! returns if file is open
bool isOpen() const;
......@@ -49,7 +49,7 @@ namespace io
core::stringc Filename;
FILE* File;
s32 FileSize;
long FileSize;
};
} // end namespace io
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment