This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BZ #1190: stream behaviour on encountering an EOF


On Thu, Sep 13, 2012 at 10:08:52AM -0700, Roland McGrath wrote:
> I know there is long history and debate about "sticky EOF" behavior in
> stdio.  I don't recall the details.  It really does not seem like a safe
> thing to change at this stage.

We have the correct behavior in musl and I have not received any
reports of programs breaking due to it. Also, I suspect most
non-GNU/Linux unices have the conformant behavior, so I doubt any
programs widely used on multiple unices break with the correct
behavior. The only programs that seem like they might have a
significant chance of breakage are very GNU/Linux-centric stuff like
util-linux, tools related to Linux network/firewall config, modules,
init & system startup, etc. and I doubt many of them are using stdio
to read from terminal devices (the only major case where EOF is a
transient condition on the underlying fd).

I think fixing this is A LOT SAFER than opponents fo the fix argue.

> Before even considering it, someone needs to do an independent, thorough
> analysis of the clauses in the standards that are purported to require a
> different behavior here.  The original bug report mentioned some POSIX
> references, but we need to see here (on this list) a specific analysis of
> the wording of the specification to justify the claim about how the
> functions are supposed to behave.

The standard for fgetc is very clear:

    RETURN VALUE

    [...] If the end-of-file indicator for the stream is set, or if
    the stream is at end-of-file, the end-of-file indicator for the
    stream shall be set and fgetc() shall return EOF. [...]

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetc.html

This language is not introduced by POSIX; it's paraphrased from the
ISO C standard (7.19.7.1 of C99), which reads:

    Returns

    If the end-of-file indicator for the stream is set, or if the
    stream is at end-of-file, the end- of-file indicator for the
    stream is set and the fgetc function returns EOF. Otherwise, the
    fgetc function returns the next character from the input stream
    pointed to by stream. If a read error occurs, the error indicator
    for the stream is set and the fgetc function returns EOF.

There is no conceivable justification for glibc's behavior in terms of
the standards.

Rich


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]