[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: rationale for closein
From: |
Bruno Haible |
Subject: |
Re: rationale for closein |
Date: |
Tue, 19 Jun 2012 02:29:29 +0200 |
User-agent: |
KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; ) |
Rich Felker wrote about 'closeout':
> ... Conceptually, you're
> turning something that's a local variable ... into a global, and
> thereby losing the _local_
> information of whether it was used in the first place, which has to be
> recovered with the non-portable __fpending.
Correct. We do this because it would be too tedious to keep track,
in local variables outside of the stream, whether it was "used in the
first place".
> the same code that checks for write errors and reports failure
> for explicitly-opened files would also check and report write errors
> on stdout.
The code has been generalized: There are two (quite similar) modules
'close-stream' and 'fwriteerror'.
> > 'closein' is similar - an attempt to fix an issue that affects many
> > programs,
> > once and for all. By Eric Blake.
>
> I think closein is just a no-op for conformant implementations. exit
> implicitly closes all streams, including stdin, and per POSIX, fclose
> has the following effect:
>
> If the file is not already at EOF, and the file is one capable of
> seeking, the file offset of the underlying open file description
> shall be adjusted so that the next operation on the open file
> description deals with the byte after the last one read from or
> written to the stream being closed.
>
> As such, close_stdin's attempt to fix-up the file position seems to be
> redundant.
>
> Incidentally, I suspect musl is _not_ currently handling this case
> correctly.
And glibc is not handling it correctly either:
<http://sourceware.org/bugzilla/show_bug.cgi?id=12724>
Which is why 'closein' is needed in gnulib.
> Does gnulib have some tests that assert the required
> behavior, which I could use to test the current behavior and any
> efforts to fix it if it's wrong?
Not in gnulib. But you find two test programs attached in the bug report
from Eric, cited above.
Bruno
- Re: musl, printf out-of-memory test, (continued)
- Re: grantpt test, Bruno Haible, 2012/06/22
- Re: [musl] Re: musl bugs found through gnulib, Rich Felker, 2012/06/20
- Re: [musl] Re: musl bugs found through gnulib, Rich Felker, 2012/06/20
- Re: [musl] Re: musl bugs found through gnulib, Paul Eggert, 2012/06/21
- Message not available
- Message not available
- rationale for closein, Bruno Haible, 2012/06/18
- Re: rationale for closein, Rich Felker, 2012/06/18
- Re: rationale for closein,
Bruno Haible <=
- Re: rationale for closein, Eric Blake, 2012/06/18
- Re: rationale for closein, Rich Felker, 2012/06/18
- Re: rationale for closein, Eric Blake, 2012/06/19
- Re: rationale for closein, Rich Felker, 2012/06/19
- dlsym [was: rationale for closein], Eric Blake, 2012/06/19
- Re: rationale for closein, Paul Eggert, 2012/06/19