changeset 28245:83debf6cac6a

Prefer nl_langinfo over localeconv.
author Bruno Haible <bruno@clisp.org>
date Mon, 26 Mar 2007 02:15:46 +0000
parents d5ac22e975dc
children 413009bff3f1
files 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
diffstat 11 files changed, 66 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 26 00:28:46 2007 +0000
+++ b/ChangeLog	Mon Mar 26 02:15:46 2007 +0000
@@ -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.
--- a/lib/vasnprintf.c	Mon Mar 26 00:28:46 2007 +0000
+++ b/lib/vasnprintf.c	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
 			      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 @@
 			      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] : '.');
--- a/m4/fprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/fprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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
--- a/m4/snprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/snprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
     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
--- a/m4/sprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/sprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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
--- a/m4/vasnprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vasnprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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
 ])
--- a/m4/vasnprintf.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vasnprintf.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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_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],
 [
--- a/m4/vasprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vasprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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
--- a/m4/vfprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vfprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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
--- a/m4/vsnprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vsnprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
     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
--- a/m4/vsprintf-posix.m4	Mon Mar 26 00:28:46 2007 +0000
+++ b/m4/vsprintf-posix.m4	Mon Mar 26 02:15:46 2007 +0000
@@ -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 @@
       ;;
   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