[Scummvm-devel] eof & err

sunmax at libero.it sunmax at libero.it
Sun Jul 12 21:06:11 CEST 2009


Hi Willem!

> > if (_filePos >= _fileSize) {
> > _eof = true;
> > ...

> That code is _before_ reading, though, so that should be ok.

Yes.

Unless you immediately after check for eof (like ->err() does),
cause in this case you will always get "true".

What's going on is:

[ common/iff_container.h ]

 - parse(...) does:

   while (!stream.eos()) {
       stream.readByte();
   }

a) until eos() is false it will keep reading

b) eos() becomes true when stream.readByte tries to read past
   the last byte, so now both _eof and eos() will be true

   (see the snippet you quoted)

c) err() will then return true (<- _eof)

The fact is that eof/eos are in sync (so they are both true
or both false) in the current PS2 file implementation.

And err() returns _eof...

So when eos() is true (which is the condition to exit the
iff loop), err() will be true too.

Is that the correct semantics?

In the ReadStream eos() comments we can read:

 [ common/stream.h @ 158 ]

 "Returns true if a read failed because the stream has been
  reached."

I assume that "the stream" == "the end of the stream".

So it would seem that current PS2 implementation is correct.

Or err() should be a whole different concept than eos/eof
and we should just "return false" like the base class for
*Stream does:

  virtual bool err() const { return false; }

But then if we always return false, it's pointless to check
for err() ;-)

Thanks!
 -max





More information about the Scummvm-devel mailing list