diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-10 17:23:35 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-10 17:23:35 +0000 |
commit | 903e7a1e3d4fe99e9de7f4adc1e401ba871caec9 (patch) | |
tree | b907c597cf228d4fd58a771f1b65d559c2c01c89 /src/sfile.cpp | |
parent | b6e100b94b12f3f92ec025dc2363eaf7c0ee6662 (diff) | |
download | libbu++-903e7a1e3d4fe99e9de7f4adc1e401ba871caec9.tar.gz libbu++-903e7a1e3d4fe99e9de7f4adc1e401ba871caec9.tar.bz2 libbu++-903e7a1e3d4fe99e9de7f4adc1e401ba871caec9.tar.xz libbu++-903e7a1e3d4fe99e9de7f4adc1e401ba871caec9.zip |
Wrote some cute file unit tests, and added some more error reporting to SFile.
Also fixed the stream system to use void * pointers instead of char *.
Diffstat (limited to 'src/sfile.cpp')
-rw-r--r-- | src/sfile.cpp | 16 |
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 | ||
4 | Bu::SFile::SFile( const char *sName, const char *sFlags ) | 5 | Bu::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 | ||
9 | Bu::SFile::~SFile() | 14 | Bu::SFile::~SFile() |
@@ -20,15 +25,20 @@ void Bu::SFile::close() | |||
20 | } | 25 | } |
21 | } | 26 | } |
22 | 27 | ||
23 | size_t Bu::SFile::read( char *pBuf, size_t nBytes ) | 28 | size_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 | ||
31 | size_t Bu::SFile::write( const char *pBuf, size_t nBytes ) | 41 | size_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."); |