Prefer nl_langinfo over localeconv.
authorBruno Haible <bruno@clisp.org>
Mon, 26 Mar 2007 02:15:46 +0000 (02:15 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 26 Mar 2007 02:15:46 +0000 (02:15 +0000)
ChangeLog
lib/vasnprintf.c
m4/fprintf-posix.m4
m4/snprintf-posix.m4
m4/sprintf-posix.m4
m4/vasnprintf-posix.m4
m4/vasnprintf.m4
m4/vasprintf-posix.m4
m4/vfprintf-posix.m4
m4/vsnprintf-posix.m4
m4/vsprintf-posix.m4

index aeabcc00d74378327f7c4d2990830b93b15d491d..75d701e9326f450c228afe79b9ae45c7a8aaa899 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2007-03-25  Bruno Haible  <bruno@clisp.org>
+
+       * lib/vasnprintf.c: Include langinfo.h.
+       (VASNPRINTF): Prefer nl_langinfo over localeconv, since it's more
+       multithread-safe.
+       * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_A): New macro.
+       * m4/fprintf-posix.m4 (gl_FUNC_FPRINTF_POSIX): Invoke it.
+       * m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Likewise.
+       * m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise.
+       * m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise.
+       * m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise.
+       * m4/vfprintf-posix.m4 (gl_FUNC_VFPRINTF_POSIX): Likewise.
+       * m4/vsnprintf-posix.m4 (gl_FUNC_VSNPRINTF_POSIX: Likewise.
+       * m4/vsprintf-posix.m4 (gl_FUNC_VSPRINTF_POSIX): Likewise.
+       Reported by Simon Josefsson.
+
 2007-03-25  Bruno Haible  <bruno@clisp.org>
 
        * lib/printf-parse.c [!IN_LIBINTL]: Include <stdint.h>, for intmax_t.
index 75d33b347ea583c6a2b0edc864dd2705900a349c..ab82b2124150052b2b9a419ed03f7d12f39f5d6a 100644 (file)
@@ -41,6 +41,9 @@
 #include <errno.h>     /* errno */
 #include <limits.h>    /* CHAR_BIT */
 #include <float.h>     /* DBL_MAX_EXP, LDBL_MAX_EXP */
+#if HAVE_NL_LANGINFO
+# include <langinfo.h>
+#endif
 #if WIDE_CHAR_VERSION
 # include "wprintf-parse.h"
 #else
@@ -507,8 +510,15 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
                              if ((flags & FLAG_ALT)
                                  || mantissa > 0.0L || precision > 0)
                                {
-                                 const char *point =
-                                   localeconv () -> decimal_point;
+                                 const char *point;
+                                 /* Prefer nl_langinfo() over localeconv(),
+                                    since the latter is not multithread-
+                                    safe.  */
+#  if HAVE_NL_LANGINFO
+                                 point = nl_langinfo (RADIXCHAR);
+#  else
+                                 point = localeconv () -> decimal_point;
+#  endif
                                  /* The decimal point is always a single byte:
                                     either '.' or ','.  */
                                  *p++ = (point[0] != '\0' ? point[0] : '.');
@@ -657,8 +667,15 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
                              if ((flags & FLAG_ALT)
                                  || mantissa > 0.0 || precision > 0)
                                {
-                                 const char *point =
-                                   localeconv () -> decimal_point;
+                                 const char *point;
+                                 /* Prefer nl_langinfo() over localeconv(),
+                                    since the latter is not multithread-
+                                    safe.  */
+#  if HAVE_NL_LANGINFO
+                                 point = nl_langinfo (RADIXCHAR);
+#  else
+                                 point = localeconv () -> decimal_point;
+#  endif
                                  /* The decimal point is always a single byte:
                                     either '.' or ','.  */
                                  *p++ = (point[0] != '\0' ? point[0] : '.');
index 60e519d6069c6f6a94d776f7e3d952c8c6e88191..5566deccf455b65bc1960dde2e2934c4dfa2710e 100644 (file)
@@ -1,4 +1,4 @@
-# fprintf-posix.m4 serial 1
+# fprintf-posix.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,
@@ -31,11 +31,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
       ;;
   esac
   if test $gl_cv_func_fprintf_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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_FPRINTF
   fi
index d1f889ed88a2b9d86ff3c16d85986b5f72ceac9e..7b9e73b4cb5637ca6d269a4ae147196e33f4a12b 100644 (file)
@@ -1,4 +1,4 @@
-# snprintf-posix.m4 serial 1
+# snprintf-posix.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,
@@ -50,11 +50,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
     esac
   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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_SNPRINTF
   fi
index 99321940f56a349340ed1d02aba48a4743445467..5e6c3961bdcad935bdbd09e51aeabd3322adb497 100644 (file)
@@ -1,4 +1,4 @@
-# sprintf-posix.m4 serial 1
+# sprintf-posix.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,
@@ -31,11 +31,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
       ;;
   esac
   if test $gl_cv_func_sprintf_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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_SPRINTF
   fi
index ea282a1bb305c22cdbf49d959fcada4a1e471ab4..8c3d9779e91be7aface661bd8e3e636bdbb8a0eb 100644 (file)
@@ -1,4 +1,4 @@
-# vasnprintf-posix.m4 serial 2
+# vasnprintf-posix.m4 serial 3
 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,
@@ -34,11 +34,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
       ;;
   esac
   if test $gl_cv_func_vasnprintf_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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
   fi
 ])
index 5aa05bc61ce960d1b885e4a086f3178a0963ddca..a225c1c4786d9b566eb1a3a6fc9cdaae9b0a1eb8 100644 (file)
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 9
+# vasnprintf.m4 serial 10
 dnl Copyright (C) 2002-2004, 2006-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,
@@ -62,6 +62,18 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF],
   AC_CHECK_FUNCS(snprintf wcslen)
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A],
+[
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  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.])
+    AC_CHECK_FUNCS([nl_langinfo])
+  fi
+])
+
 # Prerequisites of lib/asnprintf.c.
 AC_DEFUN([gl_PREREQ_ASNPRINTF],
 [
index 079ac768bcae60c0848a9529769206d0f5b731c3..7ab9ab6ee4e64984440fe9a03230e972f99b3f95 100644 (file)
@@ -1,4 +1,4 @@
-# vasprintf-posix.m4 serial 2
+# vasprintf-posix.m4 serial 3
 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,
@@ -34,11 +34,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
       ;;
   esac
   if test $gl_cv_func_vasprintf_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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_VASPRINTF
   fi
index 11cbfda4270a5c23b80cc43e151fcef674ae3a53..9b4178786495388a1ee4610ccee7efb83d8b92d3 100644 (file)
@@ -1,4 +1,4 @@
-# vfprintf-posix.m4 serial 1
+# vfprintf-posix.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,
@@ -31,11 +31,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
       ;;
   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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_VFPRINTF
   fi
index c90ad8ef2e4a402695ffd534a9115a25abe3b555..f776da066a48f5bff2bbf9041b48f7f3521fa378 100644 (file)
@@ -1,4 +1,4 @@
-# vsnprintf-posix.m4 serial 1
+# vsnprintf-posix.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,
@@ -51,11 +51,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
     esac
   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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_VSNPRINTF
   fi
index ef5d2e8a196a6217a89917f93f7e1cc30c7142b0..f0b7ba93e514845435a9a7462d9fe8460c197dcf 100644 (file)
@@ -1,4 +1,4 @@
-# vsprintf-posix.m4 serial 1
+# vsprintf-posix.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,
@@ -31,11 +31,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
       ;;
   esac
   if test $gl_cv_func_vsprintf_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_PREREQ_VASNPRINTF_DIRECTIVE_A
     gl_REPLACE_VASNPRINTF
     gl_REPLACE_VSPRINTF
   fi