diff options
Diffstat (limited to '')
-rw-r--r-- | src/file.cpp | 14 |
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 @@ | |||
16 | namespace Bu { subExceptionDef( FileException ) } | 16 | namespace Bu { subExceptionDef( FileException ) } |
17 | 17 | ||
18 | Bu::File::File( const Bu::FString &sName, int iFlags ) : | 18 | Bu::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 | ||
29 | Bu::File::File( int fd ) : | 31 | Bu::File::File( int fd ) : |
30 | fd( fd ) | 32 | fd( fd ) |
31 | { | 33 | { |
34 | bEos = false; | ||
32 | } | 35 | } |
33 | 36 | ||
34 | Bu::File::~File() | 37 | Bu::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 | ||
106 | bool Bu::File::isEOS() | 114 | bool Bu::File::isEOS() |
107 | { | 115 | { |
108 | return false; | 116 | return bEos; |
109 | } | 117 | } |
110 | 118 | ||
111 | bool Bu::File::canRead() | 119 | bool Bu::File::canRead() |