mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: printf POSIX compliance
Date: Fri, 8 Jun 2012 13:00:56 -0400	[thread overview]
Message-ID: <20120608170056.GU163@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAOnWdoivcwhGoEELHZN5Pasj0eZC+bzFJ2DBfT5cuUHXT0ZCDg@mail.gmail.com>

On Fri, Jun 08, 2012 at 05:46:10PM +0100, Reuben Thomas wrote:
> On 8 June 2012 17:46, John Spencer <maillist-musl@barfooze.de> wrote:
> >
> > this is bogus, according to Rich:
> > "all files are closed when a process terminates normally/calls exit.
> >  if you want to report write failures, just fflush(stdout) before exit and
> > check the return value"
> 
> Jim Meyering has an analysis of the problem here:
> 
> http://www.gnu.org/ghm/2011/paris/#sec-2-1

He makes it a lot more difficult than it has to be. My preferred way
of handling the situation is never to close stdout at all, only to
flush it with fflush(stdout), then check ferror(stdout). This will
report any new or past write errors that weren't already cleared by
clearerr; the only errors it cannot report are error returns from the
underlying close(1) operation. Some people want to detect such errors,
in which case the following expression will reliably determine if any
error occurred:

ferror(stdout) || fclose(stdout)

With that said, I question the value of checking for errors in
close(). The only historical case where they have any consequence are
with broken NFS setups (NFS is broken beyond usability for countless
reasons, but this is getting off-topic...), where even the lack of an
error from close() cannot ensure consistency.

There's certainly not a need to do any of this with atexit functions
or other ugly hacks. Whatever error check you do, it belongs at the
point of normal program termination (or if you're handling multiple
output files, perhaps the point where you finish handling stdout).

Rich


  parent reply	other threads:[~2012-06-08 17:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-08 10:34 Reuben Thomas
2012-06-08 12:19 ` Luca Barbato
2012-06-08 12:32   ` Reuben Thomas
2012-06-08 14:04 ` Szabolcs Nagy
2012-06-08 14:16   ` Rich Felker
2012-06-08 14:44 ` Rich Felker
2012-06-08 14:55   ` Rich Felker
2012-06-08 15:06     ` Szabolcs Nagy
2012-06-08 15:29       ` Rich Felker
2012-06-08 15:43         ` Reuben Thomas
2012-06-08 15:53           ` Rich Felker
2012-06-08 16:16             ` Reuben Thomas
2012-06-08 16:38               ` John Spencer
2012-06-08 16:37                 ` Reuben Thomas
2012-06-09  7:43                   ` John Spencer
2012-06-09 14:17                     ` Reuben Thomas
2012-06-08 16:46       ` John Spencer
2012-06-08 16:46         ` Reuben Thomas
2012-06-08 16:51           ` Rich Felker
2012-06-08 16:58             ` Reuben Thomas
2012-06-08 17:00           ` Rich Felker [this message]
2012-06-08 17:07             ` Reuben Thomas
2012-06-08 23:25               ` Rich Felker
2012-06-09  2:33           ` Isaac Dunham
2012-06-09  2:45             ` Rich Felker
2012-06-09 12:58               ` Szabolcs Nagy
2012-06-09 14:17                 ` Reuben Thomas
2012-06-09 21:11                 ` Rich Felker
2012-06-09 21:24                   ` Reuben Thomas
2012-06-09 14:15               ` Reuben Thomas
2012-06-11  9:37 Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120608170056.GU163@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).