Re: getF in lauxlib.c--why call feof?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: getF in lauxlib.c--why call feof?
- From: Edgar Toernig <froese@...>
- Date: 2008年3月26日 21:51:16 +0100
Luiz Henrique de Figueiredo wrote:
>
> > /* EOF flag checked here because when lf->f is a terminal, the fread
> > may return > 0 even when it is set. If you call fread again and
> > lf->f is a terminal it will wait for the next line or CTRL-D. */
>
> Actually I think the exact problem is a little different: fread can
> return > 0 *and* set the EOF flag. The next time getF is called, if
> you call fread, then the terminal will wait for user input. By calling
> feof before fread, you avoid this wait.
How about
/*
* Trying to read past EOF or after an error exposes implemen-
* tation and device (file/tty) differences. Better not ...
*/
if (feof(lf->f) || ferror(lf->f))
return NULL;
?
Ciao, ET.