bug-gnulib
[Top][All Lists]
Advanced

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

Re: new module: xprintf


From: Eric Blake
Subject: Re: new module: xprintf
Date: Mon, 22 Oct 2007 20:11:07 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> 
> Jim Meyering <jim <at> meyering.net> writes:
> 
> > 
> > I've just added a new module:
> > 
> >     http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=78da34d40e6a2
> 
> Any objection to making this module also provide xvprintf and xvfprintf?  M4 
> has a use of vfprintf, which would be nice to have the wrapper for.

As in the following?  (Also, it fixes a C89 compiler issue).

2007-10-22  Eric Blake  <address@hidden>

        Also wrap vf?printf.
        * lib/xprintf.h (xvprintf, xvfprintf): New declarations.
        * lib/xprintf.c (xprintf, xfprintf): Work for C89.
        (xvprintf, xvfprintf): New functions.

From: Eric Blake <address@hidden>
Date: Mon, 22 Oct 2007 14:09:16 -0600
Subject: [PATCH] Also wrap vf?printf.

* lib/xprintf.h (xvprintf, xvfprintf): New declarations.
* lib/xprintf.c (xprintf, xfprintf): Work for C89.
(xvprintf, xvfprintf): New functions.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog     |    7 +++++++
 lib/xprintf.c |   27 ++++++++++++++++++++++++---
 lib/xprintf.h |    6 ++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c15c015..8fceeda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-22  Eric Blake  <address@hidden>
+
+       Also wrap vf?printf.
+       * lib/xprintf.h (xvprintf, xvfprintf): New declarations.
+       * lib/xprintf.c (xprintf, xfprintf): Work for C89.
+       (xvprintf, xvfprintf): New functions.
+
 2007-10-22  Bruno Haible  <address@hidden>
 
        * m4/ulonglong.m4 (AC_TYPE_UNSIGNED_LONG_LONG_INT): Use -1ull, not
diff --git a/lib/xprintf.c b/lib/xprintf.c
index b3940ad..7738cc4 100644
--- a/lib/xprintf.c
+++ b/lib/xprintf.c
@@ -19,7 +19,6 @@
 #include "xprintf.h"
 
 #include <errno.h>
-#include <stdarg.h>
 
 #include "error.h"
 #include "exitfail.h"
@@ -33,11 +32,22 @@ int
 xprintf (char const *restrict format, ...)
 {
   va_list args;
+  int err;
   va_start (args, format);
+  err = xvprintf (format, args);
+  va_end (args);
+
+  return err;
+}
+
+/* Just like vprintf, but call error if it fails without setting
+   the error indicator.  */
+int
+xvprintf (char const *restrict format, va_list args)
+{
   int err = vprintf (format, args);
   if (err < 0 && ! ferror (stdout))
     error (exit_failure, errno, gettext ("cannot perform formatted output"));
-  va_end (args);
 
   return err;
 }
@@ -48,11 +58,22 @@ int
 xfprintf (FILE *restrict stream, char const *restrict format, ...)
 {
   va_list args;
+  int err;
   va_start (args, format);
+  err = xvfprintf (stream, format, args);
+  va_end (args);
+
+  return err;
+}
+
+/* Just like vfprintf, but call error if it fails without setting
+   the error indicator.  */
+int
+xvfprintf (FILE *restrict stream, char const *restrict format, va_list args)
+{
   int err = vfprintf (stream, format, args);
   if (err < 0 && ! ferror (stream))
     error (exit_failure, errno, gettext ("cannot perform formatted output"));
-  va_end (args);
 
   return err;
 }
diff --git a/lib/xprintf.h b/lib/xprintf.h
index 4c0870c..5340aa3 100644
--- a/lib/xprintf.h
+++ b/lib/xprintf.h
@@ -17,6 +17,7 @@
 #ifndef _XPRINTF_H
 #define _XPRINTF_H
 
+#include <stdarg.h>
 #include <stdio.h>
 
 #ifndef __attribute__
@@ -34,7 +35,12 @@
 
 extern int xprintf (char const *restrict format, ...)
   __attribute__ ((__format__ (__printf__, 1, 2)));
+extern int xvprintf (char const *restrict format, va_list args)
+  __attribute__ ((__format__ (__printf__, 1, 0)));
 extern int xfprintf (FILE *restrict stream, char const *restrict format, ...)
   __attribute__ ((__format__ (__printf__, 2, 3)));
+extern int xvfprintf (FILE *restrict stream, char const *restrict format,
+                     va_list args)
+  __attribute__ ((__format__ (__printf__, 2, 0)));
 
 #endif
-- 
1.5.3.2








reply via email to

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