diff options
Diffstat (limited to 'src/sfile.cpp')
| -rw-r--r-- | src/sfile.cpp | 90 |
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 | |||
| 4 | Bu::SFile::SFile( const char *sName, const char *sFlags ) | ||
| 5 | { | ||
| 6 | fh = fopen( sName, sFlags ); | ||
| 7 | } | ||
| 8 | |||
| 9 | Bu::SFile::~SFile() | ||
| 10 | { | ||
| 11 | close(); | ||
| 12 | } | ||
| 13 | |||
| 14 | void Bu::SFile::close() | ||
| 15 | { | ||
| 16 | if( fh ) | ||
| 17 | { | ||
| 18 | fclose( fh ); | ||
| 19 | fh = NULL; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | size_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 | |||
| 31 | size_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 | |||
| 39 | long Bu::SFile::tell() | ||
| 40 | { | ||
| 41 | if( !fh ) | ||
| 42 | throw FileException("File not open."); | ||
| 43 | |||
| 44 | return ftell( fh ); | ||
| 45 | } | ||
| 46 | |||
| 47 | void Bu::SFile::seek( long offset ) | ||
| 48 | { | ||
| 49 | if( !fh ) | ||
| 50 | throw FileException("File not open."); | ||
| 51 | |||
| 52 | fseek( fh, offset, SEEK_CUR ); | ||
| 53 | } | ||
| 54 | |||
| 55 | void Bu::SFile::setPos( long pos ) | ||
| 56 | { | ||
| 57 | if( !fh ) | ||
| 58 | throw FileException("File not open."); | ||
| 59 | |||
| 60 | fseek( fh, pos, SEEK_SET ); | ||
| 61 | } | ||
| 62 | |||
| 63 | void Bu::SFile::setPosEnd( long pos ) | ||
| 64 | { | ||
| 65 | if( !fh ) | ||
| 66 | throw FileException("File not open."); | ||
| 67 | |||
| 68 | fseek( fh, pos, SEEK_END ); | ||
| 69 | } | ||
| 70 | |||
| 71 | bool Bu::SFile::isEOS() | ||
| 72 | { | ||
| 73 | return feof( fh ); | ||
| 74 | } | ||
| 75 | |||
| 76 | bool Bu::SFile::canRead() | ||
| 77 | { | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | |||
| 81 | bool Bu::SFile::canWrite() | ||
| 82 | { | ||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | bool Bu::SFile::canSeek() | ||
| 87 | { | ||
| 88 | return true; | ||
| 89 | } | ||
| 90 | |||
