From 90374d639f7c4cbbacaabca9cedec88f8b5bce3d Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 19 Oct 2007 22:30:06 +0200 Subject: [PATCH] * lib/xprintf.c: Don't bother testing specific errno values. Just test ferror. --- ChangeLog | 1 + lib/xprintf.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d837fc11c..eefe98544 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2007-10-19 Jim Meyering * lib/xprintf.c (xprintf, xfprintf): Test err < 0, not just "err". + Don't bother testing specific errno values. Just test ferror. New module: xprintf * modules/xprintf, lib/xprintf.c, lib/xprintf.h: New files. diff --git a/lib/xprintf.c b/lib/xprintf.c index 908fc4f11..2134e2614 100644 --- a/lib/xprintf.c +++ b/lib/xprintf.c @@ -29,29 +29,29 @@ /* written by Jim Meyering */ -/* Just like printf, but call error if it fails for any reason - for which printf does not set the stream error indicator. */ +/* Just like printf, but call error if it fails without setting + the error indicator. */ int xprintf (char const *restrict format, ...) { va_list args; va_start (args, format); int err = vprintf (format, args); - if (err < 0 && (errno == EILSEQ || errno == EINVAL || errno == ENOMEM)) + if (err < 0 && ! ferror (stdout)) error (exit_failure, errno, gettext ("write error")); return err; } -/* Just like fprintf, but call error if it fails for any reason - for which printf does not set the stream error indicator. */ +/* Just like fprintf, but call error if it fails without setting + the error indicator. */ int xfprintf (FILE *restrict stream, char const *restrict format, ...) { va_list args; va_start (args, format); int err = vfprintf (stream, format, args); - if (err < 0 && (errno == EILSEQ || errno == EINVAL || errno == ENOMEM)) + if (err < 0 && ! ferror (stream)) error (exit_failure, errno, gettext ("write error")); return err; -- 2.11.0