fgets, EOF in middle of line, does not cause error

D

Douglas A. Gwyn

On the contrary, the committee's response to DR 141 (for C89) indicates
that that was always the intended behavior; the wording changes in C99
were just a clarification, not a change.

Since this required a change in the implementation of the
library that served as a practical reference for how stdio
was supposed to work during C89 deliberations, namely the
Unix system library, it is hard to believe that this was
an intended original requirement. I seem to recall that
at least one current vendor said during the discussion
leading to the wording change that he would have to change
his implementation to conform to this requirement.

It would probably be accurate to say that some committee
members thought that sticky-EOF was a good idea all along.
However, it would also be accurate to say that others did
not.
 
C

Chris Torek

[also known as "sticky EOF"]
On the contrary, the committee's response to DR 141 (for C89) indicates
that [sticky EOF] was always the intended behavior ...

Since this required a change in the implementation of the
library that served as a practical reference for how stdio
was supposed to work during C89 deliberations, namely the
Unix system library, it is hard to believe that this was
an intended original requirement.

It only required a change in System V implementations, not in
BSD implementations.

When I wrote my stdio for 4.xBSD I left the library-tuner the option
of setting either behavior, by having __srefill(FILE *fp) check for
"sticky EOF" and including a comment:

/* SysV does not make this test; take it out for compatibility */
if (fp->_flags & __SEOF)
return EOF;
It would probably be accurate to say that some committee
members thought that sticky-EOF was a good idea all along.

It does play well with ungetc(). :)
However, it would also be accurate to say that others did not.

I think it is probably desirable. An explicit clearerr(fp)
suffices to clear the condition, for retry on an "interactive"
input device.
 
D

Dennis Ritchie

When I wrote my stdio for 4.xBSD I left the library-tuner the option
of setting either behavior, by having __srefill(FILE *fp) check for
"sticky EOF" and including a comment:

/* SysV does not make this test; take it out for compatibility */
if (fp->_flags & __SEOF)
return EOF;
....

The change in the BSD library certainly had a startling
effect on Katseff's sdb debugger, which (foolishly)
chose ^D as the "command" to scroll 10 lines in
the source being displayed. Suddenly, you were almost
unstoppably displaying all the rest of the source.

Dennis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top