summaryrefslogtreecommitdiff
path: root/src/sfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sfile.cpp')
-rw-r--r--src/sfile.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/sfile.cpp b/src/sfile.cpp
index d7c5c83..529d8cd 100644
--- a/src/sfile.cpp
+++ b/src/sfile.cpp
@@ -1,9 +1,14 @@
1#include "sfile.h" 1#include "sfile.h"
2#include "exceptions.h" 2#include "exceptions.h"
3#include <errno.h>
3 4
4Bu::SFile::SFile( const char *sName, const char *sFlags ) 5Bu::SFile::SFile( const char *sName, const char *sFlags )
5{ 6{
6 fh = fopen( sName, sFlags ); 7 fh = fopen( sName, sFlags );
8 if( fh == NULL )
9 {
10 throw Bu::FileException( errno, strerror(errno) );
11 }
7} 12}
8 13
9Bu::SFile::~SFile() 14Bu::SFile::~SFile()
@@ -20,15 +25,20 @@ void Bu::SFile::close()
20 } 25 }
21} 26}
22 27
23size_t Bu::SFile::read( char *pBuf, size_t nBytes ) 28size_t Bu::SFile::read( void *pBuf, size_t nBytes )
24{ 29{
25 if( !fh ) 30 if( !fh )
26 throw FileException("File not open."); 31 throw FileException("File not open.");
27 32
28 return fread( pBuf, 1, nBytes, fh ); 33 int nAmnt = fread( pBuf, 1, nBytes, fh );
34
35 if( nAmnt == 0 )
36 throw FileException("End of file.");
37
38 return nAmnt;
29} 39}
30 40
31size_t Bu::SFile::write( const char *pBuf, size_t nBytes ) 41size_t Bu::SFile::write( const void *pBuf, size_t nBytes )
32{ 42{
33 if( !fh ) 43 if( !fh )
34 throw FileException("File not open."); 44 throw FileException("File not open.");