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