New module 'vfprintf-posix'.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Mar 2007 02:40:14 +0000 (02:40 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 9 Mar 2007 02:40:14 +0000 (02:40 +0000)
ChangeLog
lib/stdio_.h
lib/vfprintf.c [new file with mode: 0644]
m4/stdio_h.m4
m4/vfprintf-posix.m4 [new file with mode: 0644]
modules/stdio
modules/vfprintf-posix [new file with mode: 0644]

index 4205017..2d45e69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2007-03-08  Bruno Haible  <bruno@clisp.org>
 
+       * modules/vfprintf-posix: New file.
+       * lib/vfprintf.c: New file.
+       * m4/vfprintf-posix.m4: New file.
+       * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also GNULIB_VFPRINTF_POSIX,
+       REPLACE_VFPRINTF.
+       * lib/stdio_.h (vfprintf): New declaration.
+       * modules/stdio (Makefile.am): Substitute also GNULIB_VFPRINTF_POSIX,
+       REPLACE_VFPRINTF.
+
+2007-03-08  Bruno Haible  <bruno@clisp.org>
+
        * lib/stdio_.h: Treat __need___FILE like __need_FILE.
 
 2007-03-08  Bruno Haible  <bruno@clisp.org>
index ceba8a1..0ed942e 100644 (file)
@@ -40,6 +40,20 @@ extern "C" {
 #endif
 
 
+#if @GNULIB_VFPRINTF_POSIX@
+# if @REPLACE_VFPRINTF@
+#  define vfprintf rpl_vfprintf
+extern int vfprintf (FILE *fp, const char *format, va_list args);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef vfprintf
+# define vfprintf(s,f,a) \
+    (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
+                      "use gnulib module vfprintf-posix for portable " \
+                      "POSIX compliance"), \
+     vfprintf (s, f, a))
+#endif
+
 #if @GNULIB_SNPRINTF@
 # if @REPLACE_SNPRINTF@
 #  define snprintf rpl_snprintf
diff --git a/lib/vfprintf.c b/lib/vfprintf.c
new file mode 100644 (file)
index 0000000..b73642a
--- /dev/null
@@ -0,0 +1,77 @@
+/* Formatted output to a stream.
+   Copyright (C) 2004, 2006-2007 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "fseterr.h"
+#include "vasnprintf.h"
+
+/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW.  */
+#ifndef EOVERFLOW
+# define EOVERFLOW E2BIG
+#endif
+
+/* Print formatted output to the stream FP.
+   Return string length of formatted string.  On error, return a negative
+   value.  */
+int
+vfprintf (FILE *fp, const char *format, va_list args)
+{
+  char buf[2000];
+  char *output;
+  size_t len;
+  size_t lenbuf = sizeof (buf);
+
+  output = vasnprintf (buf, &lenbuf, format, args);
+  len = lenbuf;
+
+  if (!output)
+    {
+      fseterr (fp);
+      return -1;
+    }
+
+  if (fwrite (output, 1, len, fp) < len)
+    {
+      if (output != buf)
+       {
+         int saved_errno = errno;
+         free (output);
+         errno = saved_errno;
+       }
+      return -1;
+    }
+
+  if (len > INT_MAX)
+    {
+      errno = EOVERFLOW;
+      fseterr (fp);
+      return -1;
+    }
+
+  return len;
+}
index 14e7d75..503cd34 100644 (file)
@@ -23,9 +23,11 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
 [
   GNULIB_SNPRINTF=0;       AC_SUBST([GNULIB_SNPRINTF])
   GNULIB_SPRINTF_POSIX=0;  AC_SUBST([GNULIB_SPRINTF_POSIX])
+  GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX])
   GNULIB_VSNPRINTF=0;      AC_SUBST([GNULIB_VSNPRINTF])
   GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  REPLACE_VFPRINTF=0;      AC_SUBST([REPLACE_VFPRINTF])
   REPLACE_SNPRINTF=0;      AC_SUBST([REPLACE_SNPRINTF])
   HAVE_DECL_SNPRINTF=1;    AC_SUBST([HAVE_DECL_SNPRINTF])
   REPLACE_VSNPRINTF=0;     AC_SUBST([REPLACE_VSNPRINTF])
diff --git a/m4/vfprintf-posix.m4 b/m4/vfprintf-posix.m4
new file mode 100644 (file)
index 0000000..11cbfda
--- /dev/null
@@ -0,0 +1,52 @@
+# vfprintf-posix.m4 serial 1
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
+[
+  AC_REQUIRE([gl_EOVERFLOW])
+  AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_POSITIONS])
+  gl_cv_func_vfprintf_posix=no
+  case "$gl_cv_func_printf_sizes_c99" in
+    *yes)
+      case "$gl_cv_func_printf_directive_a" in
+        *yes)
+          case "$gl_cv_func_printf_directive_n" in
+            *yes)
+              case "$gl_cv_func_printf_positions" in
+                *yes)
+                  # vfprintf exists and is already POSIX compliant.
+                  gl_cv_func_vfprintf_posix=yes
+                  ;;
+              esac
+              ;;
+          esac
+          ;;
+      esac
+      ;;
+  esac
+  if test $gl_cv_func_vfprintf_posix = no; then
+    if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1,
+        [Define if the vasnprintf implementation needs special code for
+         the 'a' and 'A' directives.])
+    fi
+    gl_REPLACE_VASNPRINTF
+    gl_REPLACE_VFPRINTF
+  fi
+])
+
+AC_DEFUN([gl_REPLACE_VFPRINTF],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_LIBOBJ([vfprintf])
+  REPLACE_VFPRINTF=1
+  gl_PREREQ_VFPRINTF
+])
+
+AC_DEFUN([gl_PREREQ_VFPRINTF], [:])
index 3a8bdf4..d4b02d4 100644 (file)
@@ -23,8 +23,10 @@ stdio.h: stdio_.h
          sed -e 's|@''ABSOLUTE_STDIO_H''@|$(ABSOLUTE_STDIO_H)|g' \
              -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
              -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
+             -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
              -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
              -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
+             -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
              -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
              -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
              -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
diff --git a/modules/vfprintf-posix b/modules/vfprintf-posix
new file mode 100644 (file)
index 0000000..1c0adb2
--- /dev/null
@@ -0,0 +1,32 @@
+Description:
+POSIX compatible vfprintf() function: print formatted output to a stream
+
+Files:
+lib/vfprintf.c
+m4/vfprintf-posix.m4
+m4/printf.m4
+
+Depends-on:
+stdio
+fseterr
+vasnprintf
+isnan-nolibm
+isnanl-nolibm
+printf-frexp
+printf-frexpl
+
+configure.ac:
+gl_FUNC_VFPRINTF_POSIX
+gl_STDIO_MODULE_INDICATOR([vfprintf-posix])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+