aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-10-31 05:44:33 +0000
committerMike Buland <eichlan@xagasoft.com>2006-10-31 05:44:33 +0000
commitbdd4bdd8615b1587974312a92219cbeab0068a7a (patch)
treec4fd27267755179327673e4fc501740d01ed9b43
parenta67fdaa1ef1e3a5eea88d19e327c05330998e8aa (diff)
downloadlibbu++-bdd4bdd8615b1587974312a92219cbeab0068a7a.tar.gz
libbu++-bdd4bdd8615b1587974312a92219cbeab0068a7a.tar.bz2
libbu++-bdd4bdd8615b1587974312a92219cbeab0068a7a.tar.xz
libbu++-bdd4bdd8615b1587974312a92219cbeab0068a7a.zip
Changed the file class to be SFile so that it will collide less, all of them
will be named like that, make life easier.
-rw-r--r--src/file.cpp37
-rw-r--r--src/sfile.cpp37
-rw-r--r--src/sfile.h (renamed from src/file.h)10
-rw-r--r--src/tests/sha1.cpp4
4 files changed, 44 insertions, 44 deletions
diff --git a/src/file.cpp b/src/file.cpp
deleted file mode 100644
index 9910b8a..0000000
--- a/src/file.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
1#include "file.h"
2#include "exceptions.h"
3
4File::File( const char *sName, const char *sFlags )
5{
6 fh = fopen( sName, sFlags );
7}
8
9File::~File()
10{
11}
12
13void File::close()
14{
15 if( fh )
16 {
17 fclose( fh );
18 fh = NULL;
19 }
20}
21
22size_t File::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
30size_t File::write( 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
diff --git a/src/sfile.cpp b/src/sfile.cpp
new file mode 100644
index 0000000..9c5f830
--- /dev/null
+++ b/src/sfile.cpp
@@ -0,0 +1,37 @@
1#include "sfile.h"
2#include "exceptions.h"
3
4SFile::SFile( const char *sName, const char *sFlags )
5{
6 fh = fopen( sName, sFlags );
7}
8
9SFile::~SFile()
10{
11}
12
13void SFile::close()
14{
15 if( fh )
16 {
17 fclose( fh );
18 fh = NULL;
19 }
20}
21
22size_t SFile::read( char *pBuf, size_t nBytes )
23{
24 if( !fh )
25 throw FileException("SFile not open.");
26
27 return fread( pBuf, 1, nBytes, fh );
28}
29
30size_t SFile::write( char *pBuf, size_t nBytes )
31{
32 if( !fh )
33 throw FileException("SFile not open.");
34
35 return fwrite( pBuf, 1, nBytes, fh );
36}
37
diff --git a/src/file.h b/src/sfile.h
index 111a8b8..f94aef7 100644
--- a/src/file.h
+++ b/src/sfile.h
@@ -1,15 +1,15 @@
1#ifndef FILE_H 1#ifndef SFILE_H
2#define FILE_H 2#define SFILE_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
6#include "stream.h" 6#include "stream.h"
7 7
8class File : public Stream 8class SFile : public Stream
9{ 9{
10public: 10public:
11 File( const char *sName, const char *sFlags ); 11 SFile( const char *sName, const char *sFlags );
12 virtual ~File(); 12 virtual ~SFile();
13 13
14 virtual void close(); 14 virtual void close();
15 virtual size_t read( char *pBuf, size_t nBytes ); 15 virtual size_t read( char *pBuf, size_t nBytes );
diff --git a/src/tests/sha1.cpp b/src/tests/sha1.cpp
index 51c5104..df3113c 100644
--- a/src/tests/sha1.cpp
+++ b/src/tests/sha1.cpp
@@ -1,5 +1,5 @@
1#include "sha1.h" 1#include "sha1.h"
2#include "file.h" 2#include "sfile.h"
3 3
4#define BS 1024 4#define BS 1024
5 5
@@ -16,7 +16,7 @@ int main( int argc, char *argv[] )
16 char buf[BS]; 16 char buf[BS];
17 17
18 Sha1 s; 18 Sha1 s;
19 File fin( *argv, "rb" ); 19 SFile fin( *argv, "rb" );
20 for(;;) 20 for(;;)
21 { 21 {
22 int nRead = fin.read( buf, BS ); 22 int nRead = fin.read( buf, BS );