aboutsummaryrefslogtreecommitdiff
path: root/src/file.cpp
diff options
context:
space:
mode:
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()