aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp
new file mode 100644
index 0000000..2f067e6
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CReadFile.cpp
@@ -0,0 +1,114 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#include "CReadFile.h"
6
7namespace irr
8{
9namespace io
10{
11
12
13CReadFile::CReadFile(const io::path& fileName)
14: File(0), FileSize(0), Filename(fileName)
15{
16 #ifdef _DEBUG
17 setDebugName("CReadFile");
18 #endif
19
20 openFile();
21}
22
23
24CReadFile::~CReadFile()
25{
26 if (File)
27 fclose(File);
28}
29
30
31//! returns how much was read
32s32 CReadFile::read(void* buffer, u32 sizeToRead)
33{
34 if (!isOpen())
35 return 0;
36
37 return (s32)fread(buffer, 1, sizeToRead, File);
38}
39
40
41//! changes position in file, returns true if successful
42//! if relativeMovement==true, the pos is changed relative to current pos,
43//! otherwise from begin of file
44bool CReadFile::seek(long finalPos, bool relativeMovement)
45{
46 if (!isOpen())
47 return false;
48
49 return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
50}
51
52
53//! returns size of file
54long CReadFile::getSize() const
55{
56 return FileSize;
57}
58
59
60//! returns where in the file we are.
61long CReadFile::getPos() const
62{
63 return ftell(File);
64}
65
66
67//! opens the file
68void CReadFile::openFile()
69{
70 if (Filename.size() == 0) // bugfix posted by rt
71 {
72 File = 0;
73 return;
74 }
75
76#if defined ( _IRR_WCHAR_FILESYSTEM )
77 File = _wfopen(Filename.c_str(), L"rb");
78#else
79 File = fopen(Filename.c_str(), "rb");
80#endif
81
82 if (File)
83 {
84 // get FileSize
85
86 fseek(File, 0, SEEK_END);
87 FileSize = getPos();
88 fseek(File, 0, SEEK_SET);
89 }
90}
91
92
93//! returns name of file
94const io::path& CReadFile::getFileName() const
95{
96 return Filename;
97}
98
99
100
101IReadFile* createReadFile(const io::path& fileName)
102{
103 CReadFile* file = new CReadFile(fileName);
104 if (file->isOpen())
105 return file;
106
107 file->drop();
108 return 0;
109}
110
111
112} // end namespace io
113} // end namespace irr
114