[Insight-developers] fail() fails on the Mac
Luis Ibanez
luis . ibanez at kitware . com
Fri, 13 Jun 2003 13:02:06 -0400
Hi,
Tracking some failing IO test on the Mac,
we ran again into the problem with the
Mac's broken implementation of
fstream.fail()
fstream.eof()
Whenver you read the last N bytes of a
file, the Mac is returning true in
fail() and eof(). This should only happen
if you try to read N+1 (or more).
Many of the ImageIO classes are using
fail() for testing their reads. Since
the solution involves to use #ifdefs
for APPLE that make the code less readable,
a new method
ReadBufferAsBinary()
was added at the level of the ImageIOBase
The method is to be used as
if( !ReadBufferAsBinary( ifstream, myBuffer, numberOfBytes ) )
{
// error during reading
}
It checks internally whether the expected
number of bytes has been read or not.
The internal test is Mac-resistant.
Please take this method into account when
writing new ImageIO classes or when modifying
the existing ones.
Luis