From: Bruno Haible Date: Fri, 19 Sep 2003 08:31:56 +0000 (+0000) Subject: Use fwriteerror(). X-Git-Tag: v0.13~242 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00f5d47dd96b7b167eb5cdca2180607afd2c5647;p=thirdparty%2Fgettext.git Use fwriteerror(). --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 3a70d7802..bd837290d 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,9 @@ +2003-09-14 Bruno Haible + + * closeout.c: Include fwriteerror.h. + (close_stdout_status): Use improved errno value from fwriteerror(). + Don't call fclose; it is be done implicitly during exit(). + 2003-09-14 Bruno Haible * fwriteerror.h: New file. diff --git a/gettext-tools/lib/closeout.c b/gettext-tools/lib/closeout.c index ab1596691..2f0ba105e 100644 --- a/gettext-tools/lib/closeout.c +++ b/gettext-tools/lib/closeout.c @@ -30,6 +30,7 @@ #include "__fpending.h" #endif #include "error.h" +#include "fwriteerror.h" #include "exit.h" #include "gettext.h" @@ -61,24 +62,12 @@ static void close_stdout_status (int status) { - int e = ferror (stdout) ? 0 : -1; - - /* If the stream's error bit is clear, use fflush without fclose. + if (fwriteerror (stdout)) + error (status, errno, "%s", _("write error")); + /* We don't need to fclose (stdout). fwriteerror (stdout) == 0 guarantees + that the implicit fclose (stdout) at program exit will succeed. This avoids a useless close(1) system call in the frequent case that no error occurred. */ - if (e) - { - if (fflush (stdout) != 0) - e = errno; - else - return; - } - - if (fclose (stdout) != 0) - e = errno; - - if (0 <= e) - error (status, e, "%s", _("write error")); } /* Close standard output, exiting with status EXIT_FAILURE on failure. */