X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fxprintf.c;h=edb97ebf1272936f8a40b22c3655b96b83999492;hb=d94bbd1eb1fc483d72397ec5dd94f7e885e12440;hp=2134e261418fbafee05bb053c404a572247a7f09;hpb=90374d639f7c4cbbacaabca9cedec88f8b5bce3d;p=pspp
diff --git a/lib/xprintf.c b/lib/xprintf.c
index 2134e26141..edb97ebf12 100644
--- a/lib/xprintf.c
+++ b/lib/xprintf.c
@@ -1,5 +1,5 @@
/* printf wrappers that fail immediately for non-file-related errors
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -14,14 +14,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-#ifdef HAVE_CONFIG_H
-# include
-#endif
+#include
#include "xprintf.h"
#include
-#include
#include "error.h"
#include "exitfail.h"
@@ -29,30 +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 ("write error"));
+ retval = xvprintf (format, args);
+ va_end (args);
- return err;
+ return retval;
}
-/* Just like fprintf, but call error if it fails without setting
- the error indicator. */
+/* 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
+ 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 ("write error"));
+ retval = xvfprintf (stream, format, args);
+ va_end (args);
+
+ 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 err;
+ return retval;
}