[Expat-discuss] Re: Beginner Problem

Fred L. Drake, Jr. fdrake@acm.org
Wed, 18 Sep 2002 11:00:20 -0400


Karl Waclawek writes:
 > I am not a Unix guy, but I have seen this a few times
 > in Expat code I have encountered, causing a problem
 > almost every time..
 > Why is fread actually returning a different value than fstat?

I don't have any sample code from this thread handy (don't recall
seeing any, but I've been swamped), so it's hard to say.  If the input
was being read in chunks, using the value from fstat() would certainly
be the wrong thing, but I'm guessing that wasn't the case here, or it
wouldn't have been a surprise or a mystery.

On Windows, there could be a proble if the file were opened in text
mode.  Though XML is generally considered text, it usually a mistake
to open the file in text mode, simply because it makes the size
reported by fstat() differ from the number of bytes provided by the
fread() calls.

If the input were a socket, short reads would certainly be possible
(and maybe common), but there wouldn't be any useful fstat() data.


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation