summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-03-07 01:59:05 +0000
committerBruno Haible <bruno@clisp.org>2007-03-07 01:59:05 +0000
commita6a6531cc5b25d5e8039a101a9c988a0f645b2d0 (patch)
tree16a295ad423967b5eb3935ded261e410096cb1b3
parent04cd5487c7cb479142c1a5f2b5c542ec75373dd2 (diff)
downloadgnulib-a6a6531cc5b25d5e8039a101a9c988a0f645b2d0.tar.gz
New module 'snprintf-posix'.
-rw-r--r--ChangeLog12
-rw-r--r--lib/stdio_.h5
-rw-r--r--m4/snprintf-posix.m440
-rw-r--r--m4/snprintf.m417
-rw-r--r--m4/stdio_h.m41
-rw-r--r--modules/snprintf-posix30
-rw-r--r--modules/stdio1
7 files changed, 102 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index ab43988184..8c31b574bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2007-03-06 Bruno Haible <bruno@clisp.org>
+ * modules/snprintf-posix: New file.
+ * m4/snprintf-posix.m4: New file.
+ * m4/snprintf.m4 (gl_REPLACE_SNPRINTF): New macro, extracted from
+ gl_FUNC_SNPRINTF.
+ (gl_FUNC_SNPRINTF): Invoke it.
+ * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Set also REPLACE_SNPRINTF.
+ * lib/stdio_.h (snprintf): Define as a replacement if REPLACE_SNPRINTF
+ is set.
+ * modules/stdio (Makefile.am): Substitute also REPLACE_SNPRINTF.
+
+2007-03-06 Bruno Haible <bruno@clisp.org>
+
* modules/vsnprintf-posix-tests: New file.
* tests/test-vsnprintf-posix.c: New file.
* tests/test-snprintf-posix.h: New file.
diff --git a/lib/stdio_.h b/lib/stdio_.h
index e48d94cd0f..b4a40727c0 100644
--- a/lib/stdio_.h
+++ b/lib/stdio_.h
@@ -41,7 +41,10 @@ extern "C" {
#if @GNULIB_SNPRINTF@
-# if !@HAVE_DECL_SNPRINTF@
+# if @REPLACE_SNPRINTF@
+# define snprintf rpl_snprintf
+# endif
+# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
extern int snprintf (char *str, size_t size, const char *format, ...);
# endif
#elif defined GNULIB_POSIXCHECK
diff --git a/m4/snprintf-posix.m4 b/m4/snprintf-posix.m4
new file mode 100644
index 0000000000..44c0dbf8ae
--- /dev/null
+++ b/m4/snprintf-posix.m4
@@ -0,0 +1,40 @@
+# snprintf-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_SNPRINTF_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_snprintf_posix=no
+ AC_CHECK_FUNCS([snprintf])
+ if test $ac_cv_func_snprintf = yes; then
+ 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
+ # snprintf exists and is already POSIX compliant.
+ gl_cv_func_snprintf_posix=yes
+ fi
+ fi
+ if test $gl_cv_func_snprintf_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_SNPRINTF
+ fi
+])
diff --git a/m4/snprintf.m4 b/m4/snprintf.m4
index b6f9f672d2..e5d9dd4670 100644
--- a/m4/snprintf.m4
+++ b/m4/snprintf.m4
@@ -1,4 +1,4 @@
-# snprintf.m4 serial 3
+# snprintf.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 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_SNPRINTF],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
- AC_REPLACE_FUNCS(snprintf)
- AC_CHECK_DECLS_ONCE(snprintf)
+ AC_CHECK_FUNCS([snprintf])
+ if test $ac_cv_func_snprintf = no; then
+ gl_REPLACE_SNPRINTF
+ fi
+ AC_CHECK_DECLS_ONCE([snprintf])
if test $ac_cv_have_decl_snprintf = no; then
HAVE_DECL_SNPRINTF=0
fi
+])
+
+AC_DEFUN([gl_REPLACE_SNPRINTF],
+[
+ AC_LIBOBJ([snprintf])
+ if test $ac_cv_func_snprintf = yes; then
+ REPLACE_SNPRINTF=1
+ fi
gl_PREREQ_SNPRINTF
])
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 33b59965db..79271575b4 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -24,6 +24,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF])
GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF])
dnl Assume proper GNU behavior unless another module says otherwise.
+ REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF])
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])
diff --git a/modules/snprintf-posix b/modules/snprintf-posix
new file mode 100644
index 0000000000..a5a6ac1fbf
--- /dev/null
+++ b/modules/snprintf-posix
@@ -0,0 +1,30 @@
+Description:
+POSIX compatible snprintf() function: print formatted output to a fixed length
+string
+
+Files:
+m4/snprintf-posix.m4
+m4/printf.m4
+
+Depends-on:
+snprintf
+vasnprintf
+isnan-nolibm
+isnanl-nolibm
+printf-frexp
+printf-frexpl
+
+configure.ac:
+gl_FUNC_SNPRINTF_POSIX
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/stdio b/modules/stdio
index 7eb9357582..a6e1075287 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -23,6 +23,7 @@ stdio.h: stdio_.h
sed -e 's|@''ABSOLUTE_STDIO_H''@|$(ABSOLUTE_STDIO_H)|g' \
-e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
-e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
+ -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|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' \