New module 'printf-posix'.
authorBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2007 01:20:26 +0000 (01:20 +0000)
committerBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2007 01:20:26 +0000 (01:20 +0000)
ChangeLog
lib/printf.c [new file with mode: 0644]
lib/stdio_.h
m4/printf-posix-rpl.m4 [new file with mode: 0644]
m4/stdio_h.m4
modules/printf-posix [new file with mode: 0644]
modules/stdio

index 2e783d6..e1aea64 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2007-03-09  Bruno Haible  <bruno@clisp.org>
 
+       * modules/printf-posix: New file.
+       * lib/printf.c: New file.
+       * m4/printf-posix-rpl.m4: New file.
+       * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also GNULIB_PRINTF_POSIX,
+       REPLACE_PRINTF.
+       * lib/stdio_.h (printf): New declaration.
+       (format, __format__, ____printf____, ____scanf____): New macros.
+       * modules/stdio (Makefile.am): Substitute also GNULIB_PRINTF_POSIX,
+       REPLACE_PRINTF.
+
+2007-03-09  Bruno Haible  <bruno@clisp.org>
+
        * tests/test-vasnprintf-posix2.sh: New file.
        * tests/test-vasnprintf-posix2.c: New file.
        * modules/vasnprintf-posix-tests (Files): Add them and m4/locale-fr.m4.
diff --git a/lib/printf.c b/lib/printf.c
new file mode 100644 (file)
index 0000000..1945984
--- /dev/null
@@ -0,0 +1,41 @@
+/* Formatted output to a stream.
+   Copyright (C) 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 <stdarg.h>
+
+/* Print formatted output to standard output.
+   Return string length of formatted string.  On error, return a negative
+   value.  */
+int
+printf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stdout, format, args);
+  va_end (args);
+
+  return retval;
+}
index 347ed89..18d422a 100644 (file)
@@ -68,6 +68,26 @@ extern int vfprintf (FILE *fp, const char *format, va_list args);
      vfprintf (s, f, a))
 #endif
 
+#if @GNULIB_PRINTF_POSIX@
+# if @REPLACE_PRINTF@
+/* Don't break __attribute__((format(printf,M,N))).  */
+#  define printf __printf__
+extern int printf (const char *format, ...);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef printf
+# define printf \
+    (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
+                      "use gnulib module printf-posix for portable " \
+                      "POSIX compliance"), \
+     printf)
+/* Don't break __attribute__((format(printf,M,N))).  */
+# define format(kind,m,n) format (__##kind##__, m, n)
+# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
+# define ____printf____ __printf__
+# define ____scanf____ __scanf__
+#endif
+
 #if @GNULIB_VPRINTF_POSIX@
 # if @REPLACE_VPRINTF@
 #  define vprintf rpl_vprintf
diff --git a/m4/printf-posix-rpl.m4 b/m4/printf-posix-rpl.m4
new file mode 100644 (file)
index 0000000..465fb5d
--- /dev/null
@@ -0,0 +1,23 @@
+# printf-posix-rpl.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_PRINTF_POSIX],
+[
+  AC_REQUIRE([gl_FUNC_VFPRINTF_POSIX])
+  if test $gl_cv_func_vfprintf_posix = no; then
+    gl_REPLACE_PRINTF
+  fi
+])
+
+AC_DEFUN([gl_REPLACE_PRINTF],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_LIBOBJ([printf])
+  REPLACE_PRINTF=1
+  gl_PREREQ_PRINTF
+])
+
+AC_DEFUN([gl_PREREQ_PRINTF], [:])
index db91db2..6b4170b 100644 (file)
@@ -22,6 +22,7 @@ AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
 AC_DEFUN([gl_STDIO_H_DEFAULTS],
 [
   GNULIB_FPRINTF_POSIX=0;  AC_SUBST([GNULIB_FPRINTF_POSIX])
+  GNULIB_PRINTF_POSIX=0;   AC_SUBST([GNULIB_PRINTF_POSIX])
   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])
@@ -31,6 +32,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   dnl Assume proper GNU behavior unless another module says otherwise.
   REPLACE_FPRINTF=0;       AC_SUBST([REPLACE_FPRINTF])
   REPLACE_VFPRINTF=0;      AC_SUBST([REPLACE_VFPRINTF])
+  REPLACE_PRINTF=0;        AC_SUBST([REPLACE_PRINTF])
   REPLACE_VPRINTF=0;       AC_SUBST([REPLACE_VPRINTF])
   REPLACE_SNPRINTF=0;      AC_SUBST([REPLACE_SNPRINTF])
   HAVE_DECL_SNPRINTF=1;    AC_SUBST([HAVE_DECL_SNPRINTF])
diff --git a/modules/printf-posix b/modules/printf-posix
new file mode 100644 (file)
index 0000000..ba56fa0
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+POSIX compatible printf() function: print formatted output to standard output
+
+Files:
+lib/printf.c
+m4/printf-posix-rpl.m4
+m4/printf.m4
+
+Depends-on:
+stdio
+vfprintf-posix
+
+configure.ac:
+gl_FUNC_PRINTF_POSIX
+gl_STDIO_MODULE_INDICATOR([printf-posix])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
index 6d548c1..2499d09 100644 (file)
@@ -22,6 +22,7 @@ stdio.h: stdio_.h
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
          sed -e 's|@''ABSOLUTE_STDIO_H''@|$(ABSOLUTE_STDIO_H)|g' \
              -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
+             -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|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' \
@@ -30,6 +31,7 @@ stdio.h: stdio_.h
              -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
              -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
+             -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
              -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \
              -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
              -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \