Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231216194325.23580-3-pabloyoyoista@postmarketos.org>
Date: Sat, 16 Dec 2023 20:36:44 +0100
From: Pablo Correa Gómez <pabloyoyoista@...tmarketos.org>
To: musl@...ts.openwall.com
Cc: Pablo Correa Gómez <ablocorrea@...mail.com>
Subject: [PATCH 2/2] printf: translate RADIXCHAR for floating-point numbers

From: Pablo Correa Gómez <ablocorrea@...mail.com>

This honors POSIX.1-2017, and allows to get the RADIXCHAR when the
locale is correctly translated.
---
 src/stdio/vfprintf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 497c5e19..33f98532 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -10,6 +10,7 @@
 #include <inttypes.h>
 #include <math.h>
 #include <float.h>
+#include <langinfo.h>
 
 /* Some useful macros */
 
@@ -389,7 +390,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
 			else if (s==buf+9) *--s='0';
 			out(f, s, buf+9-s);
 		}
-		if (p || (fl&ALT_FORM)) out(f, ".", 1);
+		if (p || (fl&ALT_FORM)) out(f, nl_langinfo(RADIXCHAR), 1);
 		for (; d<z && p>0; d++, p-=9) {
 			char *s = fmt_u(*d, buf+9);
 			while (s>buf) *--s='0';
@@ -404,7 +405,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
 			if (d!=a) while (s>buf) *--s='0';
 			else {
 				out(f, s++, 1);
-				if (p>0||(fl&ALT_FORM)) out(f, ".", 1);
+				if (p>0||(fl&ALT_FORM)) out(f, nl_langinfo(RADIXCHAR), 1);
 			}
 			out(f, s, MIN(buf+9-s, p));
 			p -= buf+9-s;
-- 
2.43.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.