From: "Pablo Correa Gómez" <pabloyoyoista@postmarketos.org>
To: musl@lists.openwall.com
Cc: "Pablo Correa Gómez" <ablocorrea@hotmail.com>
Subject: [musl] [PATCH 2/2] printf: translate RADIXCHAR for floating-point numbers
Date: Sat, 16 Dec 2023 20:36:44 +0100 [thread overview]
Message-ID: <20231216194325.23580-3-pabloyoyoista@postmarketos.org> (raw)
In-Reply-To: <20231216194325.23580-1-pabloyoyoista@postmarketos.org>
From: Pablo Correa Gómez <ablocorrea@hotmail.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
next prev parent reply other threads:[~2023-12-16 19:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-16 19:36 [musl] [PATCH 0/2] Support printing localized RADIXCHAR Pablo Correa Gómez
2023-12-16 19:36 ` [musl] [PATCH 1/2] langinfo: add support for LC_NUMERIC translations Pablo Correa Gómez
2023-12-16 19:36 ` Pablo Correa Gómez [this message]
2023-12-16 23:10 ` [musl] [PATCH 0/2] Support printing localized RADIXCHAR Rich Felker
2023-12-17 7:26 ` Markus Wichmann
2023-12-17 22:25 ` Pablo Correa Gomez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231216194325.23580-3-pabloyoyoista@postmarketos.org \
--to=pabloyoyoista@postmarketos.org \
--cc=ablocorrea@hotmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).