[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] addition: exit.h

From: Bruno Haible
Subject: Re: [Bug-gnulib] addition: exit.h
Date: Wed, 22 Jan 2003 13:27:21 +0100 (CET)

Karl Berry writes:
> That's good with me, but what would you think of going further and
> defining an xexit function that checks the ferror status of stdout, and
> translates 0/nonzero into EXIT_SUCCESS/EXIT_FAILURE?

As you say, xexit is a half-measure:

  - If you want that every exit(1) also checks for write error on
    stdout, then since xmalloc() and many others call exit(1), you
    need to register an atexit handler, like what 'closeout' does.

  - If, on the other hand, you don't care to see two error messages
    if there is both a normal error and an stdout write error, then
    a simple

     if (fflush (stdout) || ferror (stdout))
       error (EXIT_FAILURE, errno, _("error while writing to stdout"),

    at the end of the main function is enough.

So in the first case, xexit is not enough, and in the second case, it
is overkill.

> I adapted this as kind of a half-measure from Jim's closeout stuff since
> I wasn't prepared to figure out all the autoconf stuff to use it for
> real.

It is easy now, just copy the relevant lines from modules/closeout.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]