From: curt Date: Sat, 24 Sep 2005 12:28:14 +0000 (+0000) Subject: Add eof() support to SGIOChannel/SGFile. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7f2dfaa5b41905e31c3df92e9dda6a1db7b49ff6;p=simgear.git Add eof() support to SGIOChannel/SGFile. --- diff --git a/simgear/io/iochannel.cxx b/simgear/io/iochannel.cxx index cc6292b3..994aa89f 100644 --- a/simgear/io/iochannel.cxx +++ b/simgear/io/iochannel.cxx @@ -70,3 +70,9 @@ int SGIOChannel::writestring( const char *str ) { bool SGIOChannel::close() { return false; } + + +// dummy eof routine +bool SGIOChannel::eof() { + return false; +} diff --git a/simgear/io/iochannel.hxx b/simgear/io/iochannel.hxx index 2cfa5477..48c782a1 100644 --- a/simgear/io/iochannel.hxx +++ b/simgear/io/iochannel.hxx @@ -152,6 +152,14 @@ public: */ virtual bool close(); + /** + * The eof() method returns true if end of file has been reached + * in a context where that makes sense. Otherwise it returns + * false. + * @return result of eof check + */ + virtual bool eof(); + inline void set_type( SGChannelType t ) { type = t; } inline SGChannelType get_type() const { return type; } diff --git a/simgear/io/sg_file.cxx b/simgear/io/sg_file.cxx index 079fefec..0caf3f4a 100644 --- a/simgear/io/sg_file.cxx +++ b/simgear/io/sg_file.cxx @@ -80,7 +80,7 @@ bool SGFile::open( const SGProtocolDir d ) { int SGFile::read( char *buf, int length ) { // read a chunk ssize_t result = ::read( fp, buf, length ); - if ( result == 0 ) { + if ( length > 0 && result == 0 ) { eof_flag = true; } return result; @@ -94,7 +94,7 @@ int SGFile::readline( char *buf, int length ) { // read a chunk ssize_t result = ::read( fp, buf, length ); - if ( result == 0 ) { + if ( length > 0 && result == 0 ) { eof_flag = true; }