changeset 8363:b55fb0efed6d

New module 'vsnprintf-posix'.
author Bruno Haible <bruno@clisp.org>
date Wed, 07 Mar 2007 01:51:15 +0000
parents cc0be4662687
children 6b68eeda7e0a
files ChangeLog lib/stdio_.h m4/stdio_h.m4 m4/vsnprintf-posix.m4 m4/vsnprintf.m4 modules/stdio modules/vsnprintf-posix
diffstat 7 files changed, 104 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 07 01:39:07 2007 +0000
+++ b/ChangeLog	Wed Mar 07 01:51:15 2007 +0000
@@ -1,3 +1,15 @@
+2007-03-06  Bruno Haible  <bruno@clisp.org>
+
+	* modules/vsnprintf-posix: New file.
+	* m4/vsnprintf-posix.m4: New file.
+	* m4/vsnprintf.m4 (gl_REPLACE_VSNPRINTF): New macro, extracted from
+	gl_FUNC_VSNPRINTF.
+	(gl_FUNC_VSNPRINTF): Invoke it.
+	* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also REPLACE_VSNPRINTF.
+	* lib/stdio_.h (vsnprintf): Define as a replacement if
+	REPLACE_VSNPRINTF is set.
+	* modules/stdio (Makefile.am): Substitute also REPLACE_VSNPRINTF.
+
 2007-03-06  Bruno Haible  <bruno@clisp.org>
 
 	* m4/vasnprintf.m4 (gl_REPLACE_VASNPRINTF): Test for vasnprintf here.
--- a/lib/stdio_.h	Wed Mar 07 01:39:07 2007 +0000
+++ b/lib/stdio_.h	Wed Mar 07 01:51:15 2007 +0000
@@ -53,7 +53,10 @@
 #endif
 
 #if @GNULIB_VSNPRINTF@
-# if !@HAVE_DECL_VSNPRINTF@
+# if @REPLACE_VSNPRINTF@
+#  define vsnprintf rpl_vsnprintf
+# endif
+# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
 extern int vsnprintf (char *str, size_t size, const char *format, va_list args);
 # endif
 #elif defined GNULIB_POSIXCHECK
--- a/m4/stdio_h.m4	Wed Mar 07 01:39:07 2007 +0000
+++ b/m4/stdio_h.m4	Wed Mar 07 01:51:15 2007 +0000
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 1
+# stdio_h.m4 serial 2
 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,
@@ -25,5 +25,6 @@
   GNULIB_VSNPRINTF=0;    AC_SUBST([GNULIB_VSNPRINTF])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_SNPRINTF=1;  AC_SUBST([HAVE_DECL_SNPRINTF])
+  REPLACE_VSNPRINTF=0;   AC_SUBST([REPLACE_VSNPRINTF])
   HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF])
 ])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/vsnprintf-posix.m4	Wed Mar 07 01:51:15 2007 +0000
@@ -0,0 +1,41 @@
+# vsnprintf-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_VSNPRINTF_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_vsnprintf_posix=no
+  AC_CHECK_FUNCS([vsnprintf])
+  if test $ac_cv_func_vsnprintf = yes; then
+    dnl Assume that if vsnprintf() exists, snprintf() also exists.
+    gl_SNPRINTF_TRUNCATION_C99
+    gl_SNPRINTF_RETVAL_C99
+    gl_SNPRINTF_DIRECTIVE_N
+    if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_snprintf_truncation_c99" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_snprintf_retval_c99" : ".*yes" > /dev/null \
+       && expr "$gl_cv_func_snprintf_directive_n" : ".*yes" > /dev/null; then
+      # vsnprintf exists and is already POSIX compliant.
+      gl_cv_func_vsnprintf_posix=yes
+    fi
+  fi
+  if test $gl_cv_func_vsnprintf_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_VSNPRINTF
+  fi
+])
--- a/m4/vsnprintf.m4	Wed Mar 07 01:39:07 2007 +0000
+++ b/m4/vsnprintf.m4	Wed Mar 07 01:51:15 2007 +0000
@@ -1,4 +1,4 @@
-# vsnprintf.m4 serial 3
+# vsnprintf.m4 serial 4
 dnl Copyright (C) 2002, 2003, 2004, 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,
@@ -7,11 +7,22 @@
 AC_DEFUN([gl_FUNC_VSNPRINTF],
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
-  AC_REPLACE_FUNCS(vsnprintf)
-  AC_CHECK_DECLS_ONCE(vsnprintf)
+  AC_CHECK_FUNCS([vsnprintf])
+  if test $ac_cv_func_vsnprintf = no; then
+    gl_REPLACE_VSNPRINTF
+  fi
+  AC_CHECK_DECLS_ONCE([vsnprintf])
   if test $ac_cv_have_decl_vsnprintf = no; then
     HAVE_DECL_VSNPRINTF=0
   fi
+])
+
+AC_DEFUN([gl_REPLACE_VSNPRINTF],
+[
+  AC_LIBOBJ([vsnprintf])
+  if test $ac_cv_func_vsnprintf = yes; then
+    REPLACE_VSNPRINTF=1
+  fi
   gl_PREREQ_VSNPRINTF
 ])
 
--- a/modules/stdio	Wed Mar 07 01:39:07 2007 +0000
+++ b/modules/stdio	Wed Mar 07 01:51:15 2007 +0000
@@ -24,6 +24,7 @@
 	      -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
 	      -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
 	      -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \
+	      -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \
 	      -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/stdio_.h; \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/vsnprintf-posix	Wed Mar 07 01:51:15 2007 +0000
@@ -0,0 +1,30 @@
+Description:
+POSIX compatible vsnprintf() function: print formatted output to a fixed length
+string
+
+Files:
+m4/vsnprintf-posix.m4
+m4/printf.m4
+
+Depends-on:
+vsnprintf
+vasnprintf
+isnan-nolibm
+isnanl-nolibm
+printf-frexp
+printf-frexpl
+
+configure.ac:
+gl_FUNC_VSNPRINTF_POSIX
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+