From: curt Date: Fri, 23 Sep 2005 20:13:43 +0000 (+0000) Subject: Add an eof() method to SGFile. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fd126746f7793ad3d9aa407179d69ca4d13e82c6;p=simgear.git Add an eof() method to SGFile. --- diff --git a/simgear/io/sg_file.cxx b/simgear/io/sg_file.cxx index cd7fa1d5..079fefec 100644 --- a/simgear/io/sg_file.cxx +++ b/simgear/io/sg_file.cxx @@ -39,6 +39,7 @@ SG_USING_STD(string); SGFile::SGFile( const string &file) { set_type( sgFileType ); file_name = file; + eof_flag = true; } @@ -70,6 +71,7 @@ bool SGFile::open( const SGProtocolDir d ) { return false; } + eof_flag = false; return true; } @@ -77,7 +79,11 @@ bool SGFile::open( const SGProtocolDir d ) { // read a block of data of specified size int SGFile::read( char *buf, int length ) { // read a chunk - return ::read( fp, buf, length ); + ssize_t result = ::read( fp, buf, length ); + if ( result == 0 ) { + eof_flag = true; + } + return result; } @@ -87,7 +93,10 @@ int SGFile::readline( char *buf, int length ) { int pos = lseek( fp, 0, SEEK_CUR ); // read a chunk - int result = ::read( fp, buf, length ); + ssize_t result = ::read( fp, buf, length ); + if ( result == 0 ) { + eof_flag = true; + } // find the end of line and reset position int i; @@ -130,5 +139,6 @@ bool SGFile::close() { return false; } + eof_flag = true; return true; } diff --git a/simgear/io/sg_file.hxx b/simgear/io/sg_file.hxx index f0297633..ab3f7be0 100644 --- a/simgear/io/sg_file.hxx +++ b/simgear/io/sg_file.hxx @@ -54,6 +54,7 @@ class SGFile : public SGIOChannel { string file_name; int fp; + bool eof_flag; public: @@ -89,6 +90,9 @@ public: /** @return the name of the file being manipulated. */ inline string get_file_name() const { return file_name; } + + /** @return true of eof conditions exists */ + inline bool eof() const { return eof_flag; }; };