1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "CReadFile.h"
\r
13 CReadFile::CReadFile(const io::path& fileName)
\r
14 : File(0), FileSize(0), Filename(fileName)
\r
17 setDebugName("CReadFile");
\r
24 CReadFile::~CReadFile()
\r
31 //! returns how much was read
\r
32 size_t CReadFile::read(void* buffer, size_t sizeToRead)
\r
37 return fread(buffer, 1, sizeToRead, File);
\r
41 //! changes position in file, returns true if successful
\r
42 //! if relativeMovement==true, the pos is changed relative to current pos,
\r
43 //! otherwise from begin of file
\r
44 bool CReadFile::seek(long finalPos, bool relativeMovement)
\r
49 return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
\r
53 //! returns size of file
\r
54 long CReadFile::getSize() const
\r
60 //! returns where in the file we are.
\r
61 long CReadFile::getPos() const
\r
68 void CReadFile::openFile()
\r
70 if (Filename.size() == 0) // bugfix posted by rt
\r
76 File = fopen(Filename.c_str(), "rb");
\r
82 fseek(File, 0, SEEK_END);
\r
83 FileSize = getPos();
\r
84 fseek(File, 0, SEEK_SET);
\r
89 //! returns name of file
\r
90 const io::path& CReadFile::getFileName() const
\r
96 IReadFile* CReadFile::createReadFile(const io::path& fileName)
\r
98 CReadFile* file = new CReadFile(fileName);
\r
107 } // end namespace io
\r
108 } // end namespace irr
\r