summaryrefslogtreecommitdiff
path: root/src/file.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-07-31 17:53:02 +0000
committerMike Buland <eichlan@xagasoft.com>2009-07-31 17:53:02 +0000
commitac5fb6be210b63fd7216541679f513dc97491ede (patch)
treeacbc8a91933f9e200d51f9a58f4f7b05173611ab /src/file.cpp
parent6070f3cb3fe44f17114fd58792055e9c91bd3576 (diff)
downloadlibbu++-ac5fb6be210b63fd7216541679f513dc97491ede.tar.gz
libbu++-ac5fb6be210b63fd7216541679f513dc97491ede.tar.bz2
libbu++-ac5fb6be210b63fd7216541679f513dc97491ede.tar.xz
libbu++-ac5fb6be210b63fd7216541679f513dc97491ede.zip
Wow, Bu::Base64 had a bug about premature end of stream / not base64 data, now
it throws exceptions. It'll still try to process bad data for a while though. Also, it turns out that Bu::File never reported EOS, now it does, appropriately. I'm about to change Bu::Stream::isEOS to be Bu::Stream::isEos, this is your warning.
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/file.cpp b/src/file.cpp
index b22461a..0b9bff2 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -16,7 +16,8 @@
16namespace Bu { subExceptionDef( FileException ) } 16namespace Bu { subExceptionDef( FileException ) }
17 17
18Bu::File::File( const Bu::FString &sName, int iFlags ) : 18Bu::File::File( const Bu::FString &sName, int iFlags ) :
19 fd( -1 ) 19 fd( -1 ),
20 bEos( true )
20{ 21{
21 fd = ::open( sName.getStr(), getPosixFlags( iFlags ), 0666 ); 22 fd = ::open( sName.getStr(), getPosixFlags( iFlags ), 0666 );
22 if( fd < 0 ) 23 if( fd < 0 )
@@ -24,11 +25,13 @@ Bu::File::File( const Bu::FString &sName, int iFlags ) :
24 throw Bu::FileException( errno, "%s: %s", 25 throw Bu::FileException( errno, "%s: %s",
25 strerror(errno), sName.getStr() ); 26 strerror(errno), sName.getStr() );
26 } 27 }
28 bEos = false;
27} 29}
28 30
29Bu::File::File( int fd ) : 31Bu::File::File( int fd ) :
30 fd( fd ) 32 fd( fd )
31{ 33{
34 bEos = false;
32} 35}
33 36
34Bu::File::~File() 37Bu::File::~File()
@@ -46,6 +49,7 @@ void Bu::File::close()
46 strerror(errno) ); 49 strerror(errno) );
47 } 50 }
48 fd = -1; 51 fd = -1;
52 bEos = true;
49 } 53 }
50} 54}
51 55
@@ -55,7 +59,11 @@ size_t Bu::File::read( void *pBuf, size_t nBytes )
55 throw FileException("File not open."); 59 throw FileException("File not open.");
56 60
57 ssize_t iRead = ::read( fd, pBuf, nBytes ); 61 ssize_t iRead = ::read( fd, pBuf, nBytes );
58 if( iRead < 0 ) 62 if( iRead == 0 )
63 bEos = true;
64 else if( iRead == -1 && errno == EAGAIN )
65 return 0;
66 else if( iRead < 0 )
59 throw FileException( errno, "%s", strerror( errno ) ); 67 throw FileException( errno, "%s", strerror( errno ) );
60 return iRead; 68 return iRead;
61} 69}
@@ -105,7 +113,7 @@ void Bu::File::setPosEnd( long pos )
105 113
106bool Bu::File::isEOS() 114bool Bu::File::isEOS()
107{ 115{
108 return false; 116 return bEos;
109} 117}
110 118
111bool Bu::File::canRead() 119bool Bu::File::canRead()