summaryrefslogtreecommitdiff
path: root/src/sfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sfile.cpp')
-rw-r--r--src/sfile.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/sfile.cpp b/src/sfile.cpp
new file mode 100644
index 0000000..d7c5c83
--- /dev/null
+++ b/src/sfile.cpp
@@ -0,0 +1,90 @@
1#include "sfile.h"
2#include "exceptions.h"
3
4Bu::SFile::SFile( const char *sName, const char *sFlags )
5{
6 fh = fopen( sName, sFlags );
7}
8
9Bu::SFile::~SFile()
10{
11 close();
12}
13
14void Bu::SFile::close()
15{
16 if( fh )
17 {
18 fclose( fh );
19 fh = NULL;
20 }
21}
22
23size_t Bu::SFile::read( char *pBuf, size_t nBytes )
24{
25 if( !fh )
26 throw FileException("File not open.");
27
28 return fread( pBuf, 1, nBytes, fh );
29}
30
31size_t Bu::SFile::write( const char *pBuf, size_t nBytes )
32{
33 if( !fh )
34 throw FileException("File not open.");
35
36 return fwrite( pBuf, 1, nBytes, fh );
37}
38
39long Bu::SFile::tell()
40{
41 if( !fh )
42 throw FileException("File not open.");
43
44 return ftell( fh );
45}
46
47void Bu::SFile::seek( long offset )
48{
49 if( !fh )
50 throw FileException("File not open.");
51
52 fseek( fh, offset, SEEK_CUR );
53}
54
55void Bu::SFile::setPos( long pos )
56{
57 if( !fh )
58 throw FileException("File not open.");
59
60 fseek( fh, pos, SEEK_SET );
61}
62
63void Bu::SFile::setPosEnd( long pos )
64{
65 if( !fh )
66 throw FileException("File not open.");
67
68 fseek( fh, pos, SEEK_END );
69}
70
71bool Bu::SFile::isEOS()
72{
73 return feof( fh );
74}
75
76bool Bu::SFile::canRead()
77{
78 return true;
79}
80
81bool Bu::SFile::canWrite()
82{
83 return true;
84}
85
86bool Bu::SFile::canSeek()
87{
88 return true;
89}
90