[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: getF in lauxlib.c--why call feof?
- From: Daniel Stephens <daniel@...>
- Date: Tue, 25 Mar 2008 10:55:43 -0700
Luiz Henrique de Figueiredo wrote:
Why is it necessary to call feof before the fread? Won't fread return
0 if feof returns true? It seems that fread correctly handles the case
The man page says:
fread does not distinguish between end-of-file and error, and callers
must use feof(3) and ferror(3) to determine which occurred.
Lua doesn't appear to be using it that way (In that usage the call to
feof is made AFTER fread returns 0, in order to figure out why), because
feof is called before, and the end result is identical to that obtained
if feof returns false and fread then returns 0.
/usually/ feof is called after fread fails because you dont always know
you're at the end until you try reading past it.
(Certainly lua isn't doing anything /wrong/ here, but the call does seem