From 794283a4bb176e313b3a7a7fc5d320e37881a0be Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sat, 10 Mar 2007 00:20:53 +0000
Subject: [PATCH] The decimal point must be locale dependent.

---
 ChangeLog        |  5 +++++
 lib/vasnprintf.c | 13 +++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fc237af4e0..c305aa5cc4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-03-09  Bruno Haible  <bruno@clisp.org>
+
+	* lib/vasnprintf.c (VASNPRINTF): For the 'a' and 'A' directives, use
+	a locale dependent decimal point, rather than always '.'.
+
 2007-03-09  Eric Blake  <ebb9@byu.net>
 
 	* lib/stdlib_.h (EXIT_FAILURE): GNU code expects this to be 1, in
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index aff0b172ed..a0523ec1fb 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -34,6 +34,7 @@
 # include "vasnprintf.h"
 #endif
 
+#include <locale.h>	/* localeconv() */
 #include <stdio.h>	/* snprintf(), sprintf() */
 #include <stdlib.h>	/* abort(), malloc(), realloc(), free() */
 #include <string.h>	/* memcpy(), strlen() */
@@ -492,7 +493,11 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
 			      if ((flags & FLAG_ALT)
 				  || mantissa > 0.0L || precision > 0)
 				{
-				  *p++ = '.';
+				  const char *point =
+				    localeconv () -> decimal_point;
+				  /* The decimal point is always a single byte:
+				     either '.' or ','.  */
+				  *p++ = (point[0] != '\0' ? point[0] : '.');
 				  /* This loop terminates because we assume
 				     that FLT_RADIX is a power of 2.  */
 				  while (mantissa > 0.0L)
@@ -636,7 +641,11 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
 			      if ((flags & FLAG_ALT)
 				  || mantissa > 0.0 || precision > 0)
 				{
-				  *p++ = '.';
+				  const char *point =
+				    localeconv () -> decimal_point;
+				  /* The decimal point is always a single byte:
+				     either '.' or ','.  */
+				  *p++ = (point[0] != '\0' ? point[0] : '.');
 				  /* This loop terminates because we assume
 				     that FLT_RADIX is a power of 2.  */
 				  while (mantissa > 0.0)
-- 
2.30.2