X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fxprintf.c;h=8f279faf41b00f553bff69841f85ed40e0866241;hb=e2cf2fc52c5555b25c25171171e82dffdfe95fb1;hp=b3940ad49d2b788427de94d89399cebbd93ddebb;hpb=36454274190b141a37308d9b266b3d0b68a71694;p=gnulib.git diff --git a/lib/xprintf.c b/lib/xprintf.c index b3940ad49..8f279faf4 100644 --- a/lib/xprintf.c +++ b/lib/xprintf.c @@ -19,7 +19,6 @@ #include "xprintf.h" #include -#include #include "error.h" #include "exitfail.h" @@ -27,32 +26,54 @@ /* written by Jim Meyering */ -/* Just like printf, but call error if it fails without setting - the error indicator. */ +/* Just like printf, but call error if it fails without setting the + stream's error indicator. */ int xprintf (char const *restrict format, ...) { va_list args; + int retval; va_start (args, format); - int err = vprintf (format, args); - if (err < 0 && ! ferror (stdout)) - error (exit_failure, errno, gettext ("cannot perform formatted output")); + retval = xvprintf (format, args); va_end (args); - return err; + return retval; +} + +/* Just like vprintf, but call error if it fails without setting the + stream's error indicator. */ +int +xvprintf (char const *restrict format, va_list args) +{ + int retval = vprintf (format, args); + if (retval < 0 && ! ferror (stdout)) + error (exit_failure, errno, gettext ("cannot perform formatted output")); + + return retval; } -/* Just like fprintf, but call error if it fails without setting - the error indicator. */ +/* Just like fprintf, but call error if it fails without setting the + stream's error indicator. */ int xfprintf (FILE *restrict stream, char const *restrict format, ...) { va_list args; + int retval; va_start (args, format); - int err = vfprintf (stream, format, args); - if (err < 0 && ! ferror (stream)) - error (exit_failure, errno, gettext ("cannot perform formatted output")); + retval = xvfprintf (stream, format, args); va_end (args); - return err; + return retval; +} + +/* Just like vfprintf, but call error if it fails without setting the + stream's error indicator. */ +int +xvfprintf (FILE *restrict stream, char const *restrict format, va_list args) +{ + int retval = vfprintf (stream, format, args); + if (retval < 0 && ! ferror (stream)) + error (exit_failure, errno, gettext ("cannot perform formatted output")); + + return retval; }