>From 6c547ae824df7d1880e6163e46943259c03d4a51 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 2 Oct 2026 21:45:03 -0400 Subject: [PATCH 03/10] printf: honor locale-specific radix point a weak version of __radixpt is provided so that no locale machinery is pulled into a static link that does not call setlocale/newlocale. the radix point will always be a single-byte character '.' or ',' so there is no change to the output length logic. --- src/stdio/vfprintf.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index e0c09e45..059db93f 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -10,6 +10,7 @@ #include #include #include +#include "locale_impl.h" /* Some useful macros */ @@ -178,6 +179,12 @@ static char *fmt_u(uintmax_t x, char *s) typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)]; #endif +static int c_radixpt(locale_t loc) +{ + return '.'; +} +weak_alias(c_radixpt, __radixpt); + static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps) { int max_mant_dig = (ps==BIGLPRE) ? LDBL_MANT_DIG : DBL_MANT_DIG; @@ -244,7 +251,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps) int x=y; *s++=xdigits[x]|(t&32); y=16*(y-x); - if (s-buf==1 && (y||p>0||(fl&ALT_FORM))) *s++='.'; + if (s-buf==1 && (y||p>0||(fl&ALT_FORM))) *s++=__radixpt(0); } while (y); if (p > INT_MAX-2-(ebuf-estr)-pl) @@ -389,7 +396,10 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps) 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)) { + int radixpt = __radixpt(0); + out(f, (char[]){radixpt}, 1); + } for (; d0; d++, p-=9) { char *s = fmt_u(*d, buf+9); while (s>buf) *--s='0'; @@ -404,7 +414,10 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps) 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)) { + int radixpt = __radixpt(0); + out(f, (char[]){radixpt}, 1); + } } out(f, s, MIN(buf+9-s, p)); p -= buf+9-s; -- 2.21.0