]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Work around two grouping bugs on native Windows.
authorBruno Haible <bruno@clisp.org>
Sat, 12 Apr 2025 09:03:45 +0000 (11:03 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 12 Apr 2025 09:03:45 +0000 (11:03 +0200)
* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_FLAG_GROUPING): On native
Windows, define NEED_PRINTF_FLAG_GROUPING.
* lib/vasnprintf.c (localeconv): Undefine.
(thousands_separator_char, thousands_separator_wchar): On native
Windows, use localeconv().
* tests/test-vasnprintf-posix2.c (main): On native Windows, expect
3 digits for the exponent.
* tests/test-vasnwprintf-posix2.c (main): Likewise.
* doc/posix-functions/fprintf.texi: Mention the mingw and MSVC bugs.
* doc/posix-functions/vfprintf.texi: Likewise.
* doc/posix-functions/printf.texi: Likewise.
* doc/posix-functions/vprintf.texi: Likewise.
* doc/posix-functions/sprintf.texi: Likewise.
* doc/posix-functions/vsprintf.texi: Likewise.
* doc/posix-functions/snprintf.texi: Likewise.
* doc/posix-functions/vsnprintf.texi: Likewise.
* doc/posix-functions/dprintf.texi: Likewise.
* doc/posix-functions/vdprintf.texi: Likewise.
* doc/posix-functions/fwprintf.texi: Likewise.
* doc/posix-functions/vfwprintf.texi: Likewise.
* doc/posix-functions/wprintf.texi: Likewise.
* doc/posix-functions/vwprintf.texi: Likewise.
* doc/posix-functions/swprintf.texi: Likewise.
* doc/posix-functions/vswprintf.texi: Likewise.
* doc/posix-functions/asprintf.texi: Likewise.
* doc/posix-functions/vasprintf.texi: Likewise.
* doc/glibc-functions/obstack_printf.texi: Likewise.
* doc/glibc-functions/obstack_vprintf.texi: Likewise.

26 files changed:
ChangeLog
doc/glibc-functions/obstack_printf.texi
doc/glibc-functions/obstack_vprintf.texi
doc/posix-functions/asprintf.texi
doc/posix-functions/dprintf.texi
doc/posix-functions/fprintf.texi
doc/posix-functions/fwprintf.texi
doc/posix-functions/printf.texi
doc/posix-functions/snprintf.texi
doc/posix-functions/sprintf.texi
doc/posix-functions/swprintf.texi
doc/posix-functions/vasprintf.texi
doc/posix-functions/vdprintf.texi
doc/posix-functions/vfprintf.texi
doc/posix-functions/vfwprintf.texi
doc/posix-functions/vprintf.texi
doc/posix-functions/vsnprintf.texi
doc/posix-functions/vsprintf.texi
doc/posix-functions/vswprintf.texi
doc/posix-functions/vwprintf.texi
doc/posix-functions/wprintf.texi
lib/vasnprintf.c
m4/printf.m4
m4/vasnprintf.m4
tests/test-vasnprintf-posix2.c
tests/test-vasnwprintf-posix2.c

index e8f3874c09ef3f7a13019aed2c75d7668de77a73..5deaa6a969663e9356f4a4d67f3eafc4cec22aa8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2025-04-12  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Work around two grouping bugs on native Windows.
+       * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_FLAG_GROUPING): On native
+       Windows, define NEED_PRINTF_FLAG_GROUPING.
+       * lib/vasnprintf.c (localeconv): Undefine.
+       (thousands_separator_char, thousands_separator_wchar): On native
+       Windows, use localeconv().
+       * tests/test-vasnprintf-posix2.c (main): On native Windows, expect
+       3 digits for the exponent.
+       * tests/test-vasnwprintf-posix2.c (main): Likewise.
+       * doc/posix-functions/fprintf.texi: Mention the mingw and MSVC bugs.
+       * doc/posix-functions/vfprintf.texi: Likewise.
+       * doc/posix-functions/printf.texi: Likewise.
+       * doc/posix-functions/vprintf.texi: Likewise.
+       * doc/posix-functions/sprintf.texi: Likewise.
+       * doc/posix-functions/vsprintf.texi: Likewise.
+       * doc/posix-functions/snprintf.texi: Likewise.
+       * doc/posix-functions/vsnprintf.texi: Likewise.
+       * doc/posix-functions/dprintf.texi: Likewise.
+       * doc/posix-functions/vdprintf.texi: Likewise.
+       * doc/posix-functions/fwprintf.texi: Likewise.
+       * doc/posix-functions/vfwprintf.texi: Likewise.
+       * doc/posix-functions/wprintf.texi: Likewise.
+       * doc/posix-functions/vwprintf.texi: Likewise.
+       * doc/posix-functions/swprintf.texi: Likewise.
+       * doc/posix-functions/vswprintf.texi: Likewise.
+       * doc/posix-functions/asprintf.texi: Likewise.
+       * doc/posix-functions/vasprintf.texi: Likewise.
+       * doc/glibc-functions/obstack_printf.texi: Likewise.
+       * doc/glibc-functions/obstack_vprintf.texi: Likewise.
+
 2025-04-12  Bruno Haible  <bruno@clisp.org>
 
        localeconv tests: Add multithread-safety test.
index c96a674ac2d9a99ac4ce348771fdc5f28a75a544..34f2b9fd378308a5e6c3ac80d81eb8d722a50927 100644 (file)
@@ -42,6 +42,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 5fe389c4863cead8e323219f9ce2cb11390def74..92b0efab9b50d212c6af48ab07d20729ca32ebcf 100644 (file)
@@ -42,6 +42,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index dbbed305b5867ded526229d36d0288707daed7a9..ae6a25291542ee6419189733151cc64f4e574952 100644 (file)
@@ -68,6 +68,14 @@ This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag on some platforms:
 NetBSD 3.0, Cygwin 1.5.24.
 @item
index da9446ae99de4258130b52432cfc4ffee1c931f7..6f6dc4cfbd3b75ee25212eb776f1905769332c58 100644 (file)
@@ -28,6 +28,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 407ad6bc306ae46147eb385230aefc7591616833..4eebaafd8f043d5dc79324f65bb14425663a8a37 100644 (file)
@@ -55,6 +55,14 @@ This function does not support format directives that access arguments in an
 arbitrary order, such as @code{"%2$s"}, on some platforms:
 NetBSD 3.0, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag on some platforms:
 NetBSD 3.0, Cygwin 1.5.24, mingw, MSVC 14.
 @item
index 0dd8ec828a6f20604777937a28b0181a185fef82..3ca62ddd2f2d479dc755cc205d2e169cb512f783 100644 (file)
@@ -24,6 +24,14 @@ This function does not support size specifiers as in C23 (@code{w8},
 @code{wf64}) on some platforms:
 glibc 2.37, musl libc, macOS 14, FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC, Android 9.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 2b2c24053143deea0f006c344855eeff9896666a..4cf38b5ba60b90e7891da916cd23c50d3af3390d 100644 (file)
@@ -30,6 +30,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index a1aea4ea4b8116d87b6f818595462db655b3c2a2..410e8164450ca9b17949be5f83afbcbbc5d6c4df 100644 (file)
@@ -43,6 +43,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 3b0bc0f7250df4f4b157ebb7a271327eb7acf55b..b0bf752fe7bb2cac0e43061ef365b99b13b4f153 100644 (file)
@@ -27,6 +27,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 944dd4798cf2caf9cf7ec4035f225cd76d488694..72cabd3ba25f8ced303644ede56f868b5be3c982 100644 (file)
@@ -60,6 +60,14 @@ characters on some platforms:
 musl libc 1.2.3,
 macOS 14, FreeBSD 13.1, NetBSD 10.0, OpenBSD 7.2, AIX 7.2, mingw.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 8805d6fb9a8d61859439f22581be2c6d97cbdb4d..7c687f2c3a1ecfed67679948316377fb525ad989 100644 (file)
@@ -45,6 +45,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 3277f6edb64ac32375bcf077ec0ec2f44a9de4b7..69c09166e96767dfb2eea7f4c50c4fa2cc6e6698 100644 (file)
@@ -28,6 +28,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index cdf1f75cc8fd9de4866b4f1fb2b820f724a79809..53516d374c6744b78a969be653b094b2d9467cd3 100644 (file)
@@ -30,6 +30,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 0e7bb752fa6b47ac578e68c67bc08cea744a23ea..f0b38bae49c3e71befa02400dc93c8c0b1eb01ec 100644 (file)
@@ -24,6 +24,14 @@ This function does not support size specifiers as in C23 (@code{w8},
 @code{wf64}) on some platforms:
 glibc 2.37, musl libc, macOS 14, FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC, Android 9.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index ad82631b32515b1dba0712f01a4fb43dddc51699..8b84f2f91ed0c033d2ffb9a549f0236df4042e52 100644 (file)
@@ -30,6 +30,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 0dc8280a7c37d22a5bda83f98ba87d17082bf730..baceea4cddc25429fc742728662499f7f94ae6dd 100644 (file)
@@ -40,6 +40,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index fb231106218a0d74fb7533d1e0d9adc48da98f32..15b6e9204e800176fda273179f05f5150ce0eea0 100644 (file)
@@ -27,6 +27,14 @@ printf @code{"%f"}, @code{"%e"}, @code{"%g"} of Infinity and NaN yields an
 incorrect result on some platforms:
 AIX 7.3, Solaris 11.4, mingw, MSVC 14.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index b237e8b086e313b0a1b2d49f71c645bf73fbb5ed..2bd0b03996f93dc24dc84df84c3df8686d9fcccf 100644 (file)
@@ -26,6 +26,14 @@ This function does not support size specifiers as in C23 (@code{w8},
 @code{wf64}) on some platforms:
 glibc 2.37, musl libc, macOS 14, FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC, Android 9.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index faa34281437c9d249bb91b6a908ff38e6aa424ed..fea34ed3fca41f1dd5cc3492a7d116eeacf2a3d4 100644 (file)
@@ -27,6 +27,14 @@ This function does not support size specifiers as in C23 (@code{w8},
 @code{wf64}) on some platforms:
 glibc 2.37, musl libc, macOS 14, FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC, Android 9.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 47353bcce86fc04c76199a7f3bdcd61549fa205e..4923552b770d9a9929c29625173d4e902415d1e2 100644 (file)
@@ -27,6 +27,14 @@ This function does not support size specifiers as in C23 (@code{w8},
 @code{wf64}) on some platforms:
 glibc 2.37, musl libc, macOS 14, FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC, Android 9.0.
 @item
+This function doesn't support the @code{'} flag at all on some platforms:
+mingw without @code{__USE_MINGW_ANSI_STDIO}, MSVC 14.
+@item
+This function doesn't support the @code{'} flag correctly for integers
+(it uses the decimal point instead of the thousands separator!)
+on some platforms:
+mingw with @code{__USE_MINGW_ANSI_STDIO}.
+@item
 This function doesn't support the @code{'} flag together with a precision
 on an integer argument correctly on some platforms:
 glibc 2.36, FreeBSD 14.0, NetBSD 10.0, Solaris 11, Cygwin 3.6.0, Haiku.
index 45e7c724a5e763371cba01d88ffd7a49f005e0cf..4152237929e41589ae0bb56d442ef069983af026 100644 (file)
 # define IF_LINT(Code) /* empty */
 #endif
 
+/* Here we need only the most basic fields of 'struct lconv', and can
+   therefore use the system's localeconv() function, without needing a
+   dependency on module 'localeconv'.  */
+#undef localeconv
+
 /* Avoid some warnings from "gcc -Wshadow".
    This file doesn't use the exp() and remainder() functions.  */
 #undef exp
@@ -409,13 +414,18 @@ decimal_point_char (void)
 static const char *
 thousands_separator_char (char stackbuf[10])
 {
-  /* Determine it in a multithread-safe way.  We know nl_langinfo is
-     multithread-safe on glibc systems, on Mac OS X systems, and on NetBSD,
-     but is not required to be multithread-safe by POSIX.  sprintf(), however,
-     is multithread-safe.  localeconv() is rarely multithread-safe.  */
+  /* Determine it in a multithread-safe way.
+     We know nl_langinfo is multithread-safe on glibc systems, on Mac OS X
+     systems, and on NetBSD, but is not required to be multithread-safe by
+     POSIX.
+     localeconv() is not guaranteed to be multithread-safe by POSIX either;
+     however, on native Windows it is (cf. test-localeconv-mt).
+     sprintf(), however, is multithread-safe.  */
 #  if HAVE_NL_LANGINFO && (__GLIBC__ || defined __UCLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __NetBSD__)
   return nl_langinfo (THOUSEP);
-#  elif 1
+#  elif defined _WIN32 && !defined __CYGWIN__
+  return localeconv () -> thousands_sep;
+#  else
   sprintf (stackbuf, "%'.0f", 1000.0);
   /* Now stackbuf = "1<thousep>000".  */
   stackbuf[strlen (stackbuf) - 3] = '\0';
@@ -425,8 +435,6 @@ thousands_separator_char (char stackbuf[10])
     strcpy (&stackbuf[1], MB_CUR_MAX > 1 ? "\302\240" : "\240");
 #   endif
   return &stackbuf[1];
-#  else
-  return localeconv () -> thousands_sep;
 #  endif
 }
 # endif
@@ -451,6 +459,20 @@ thousands_separator_wchar (wchar_t stackbuf[10])
     (wchar_t) (unsigned long) nl_langinfo (_NL_NUMERIC_THOUSANDS_SEP_WC);
   stackbuf[1] = L'\0';
   return stackbuf;
+#  elif defined _WIN32 && !defined __CYGWIN__
+  const char *tmp = localeconv () -> thousands_sep;
+  if (*tmp != '\0')
+    {
+      mbstate_t state;
+      mbszero (&state);
+      if ((int) mbrtowc (&stackbuf[0], tmp, strlen (tmp), &state) > 0)
+        stackbuf[1] = L'\0';
+      else
+        stackbuf[0] = L'\0';
+    }
+  else
+    stackbuf[0] = L'\0';
+  return stackbuf;
 #  elif defined __sun
   /* Use sprintf, because swprintf retrieves a wrong value for the
      thousands-separator wide character (e.g. (wchar_t) 0xffffffa0).  */
index 62319e4af38fa45722e4e8341b3a66b982a17cb7..4619a402529ff29eb083890bb4015c778191466f 100644 (file)
@@ -2336,10 +2336,10 @@ dnl   Cygwin 1.5.19 (2006)           #  #  .  .  #  #  #  #  #  .  #  ?  .  #  ?
 dnl   Solaris 11.4                   .  #  .  #  #  #  #  #  .  .  #  .  .  .  #  #  .  #  .  .  .  .  .  .  .  .  .  .  #  .
 dnl   Solaris 11.3                   .  #  .  .  .  #  #  #  .  .  #  .  .  .  ?  ?  .  .  .  .  .  .  .  .  .  .  .  .  #  .
 dnl   Solaris 11.0                   .  #  .  #  #  #  #  #  .  .  #  .  .  .  ?  ?  .  #  .  .  .  .  .  .  .  .  .  ?  ?  ?
-dnl   Solaris 10                     .  #  .  #  #  #  #  #  .  .  #  .  .  .  ?  ?  .  #  .  #  .  .  .  .  .  .  .  .  #  .
+dnl   Solaris 10                     .  #  .  #  #  #  #  #  .  .  #  .  .  .  #  #  .  #  .  #  .  .  .  .  .  .  .  .  #  .
 dnl   Solaris 2.6 ... 9              #  #  .  #  #  #  #  #  #  .  #  .  .  .  ?  ?  .  #  ?  #  .  .  .  #  .  .  .  ?  ?  ?
 dnl   Solaris 2.5.1                  #  #  .  #  #  #  #  #  #  .  #  .  .  .  ?  ?  .  #  ?  .  .  #  #  #  #  #  #  ?  ?  ?
-dnl   AIX 7.1                        .  #  .  #  #  #  #  #  .  .  .  .  .  .  ?  ?  .  #  .  #  .  .  .  .  .  .  .  #  .  .
+dnl   AIX 7.1                        .  #  .  #  #  #  #  #  .  .  .  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .  .  #  .  .
 dnl   AIX 5.2                        .  #  .  #  #  #  #  #  .  .  .  .  .  .  ?  ?  .  #  ?  .  .  .  .  .  .  .  .  #  ?  ?
 dnl   AIX 4.3.2, 5.1                 #  #  .  #  #  #  #  #  #  .  .  .  .  .  ?  ?  .  #  ?  .  .  .  .  #  .  .  .  #  ?  ?
 dnl   HP-UX 11.31                    .  #  .  .  .  #  #  #  .  .  .  ?  .  .  ?  ?  .  #  ?  .  .  .  .  #  #  .  .  ?  ?  ?
index 35fdbc5e9417278cccde9601a8dd4bb6f36b1854..1d040d6e0c7e837ebfad2afb952e9b74ec075db8 100644 (file)
@@ -1,5 +1,5 @@
 # vasnprintf.m4
-# serial 55
+# serial 56
 dnl Copyright (C) 2002-2004, 2006-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -357,26 +357,39 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC],
 # Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
 [
+  AC_REQUIRE([AC_CANONICAL_HOST])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING_INT_PRECISION])
   AC_REQUIRE([gl_PRINTF_FLAG_GROUPING_MULTIBYTE])
-  case "$gl_cv_func_printf_flag_grouping,$gl_cv_func_printf_flag_grouping_multibyte" in
-    *yes,*yes)
-      case "$gl_cv_func_printf_flag_grouping_int_precision" in
-        *yes)
+  case "$host_os" in
+    mingw* | windows*)
+      dnl MSVC does not support the ' flag at all.
+      dnl mingw does not support it, unless __USE_MINGW_ANSI_STDIO is defined.
+      dnl mingw also has other bugs regarding the ' flag.
+      AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
+        [Define if the vasnprintf implementation needs special code for the
+         ' flag.])
+      ;;
+    *)
+      case "$gl_cv_func_printf_flag_grouping,$gl_cv_func_printf_flag_grouping_multibyte" in
+        *yes,*yes)
+          case "$gl_cv_func_printf_flag_grouping_int_precision" in
+            *yes)
+              ;;
+            *)
+              AC_DEFINE([NEED_PRINTF_FLAG_GROUPING_INT], [1],
+                [Define if the vasnprintf implementation needs special code for the
+                 ' flag, for integer directives only.])
+              ;;
+          esac
           ;;
         *)
-          AC_DEFINE([NEED_PRINTF_FLAG_GROUPING_INT], [1],
+          AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
             [Define if the vasnprintf implementation needs special code for the
-             ' flag, for integer directives only.])
+             ' flag.])
           ;;
       esac
       ;;
-    *)
-      AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], [1],
-        [Define if the vasnprintf implementation needs special code for the
-         ' flag.])
-      ;;
   esac
 ])
 
index 1f43aa5e6e1dc56bed3fe93a6360a7129ae4d4ab..b0ba95b6677bbffe24ae9891424d91e5e8fab6b1 100644 (file)
@@ -359,16 +359,28 @@ main (int argc, char *argv[])
       size_t length;
       char *result = asnprintf (NULL, &length, "%'.5g", 3141592653.5897932386);
       ASSERT (result != NULL);
-      ASSERT (length == 10);
-      ASSERT (strcmp (result, "3,1416e+09") == 0);
+      #if defined _WIN32 && !defined __CYGWIN__
+        /* Native Windows uses 3 digits for the exponent.  */
+        ASSERT (length == 11);
+        ASSERT (strcmp (result, "3,1416e+009") == 0);
+      #else
+        ASSERT (length == 10);
+        ASSERT (strcmp (result, "3,1416e+09") == 0);
+      #endif
       free (result);
     }
     {
       size_t length;
       char *result = asnprintf (NULL, &length, "%'.5g", -3141592653.5897932386);
       ASSERT (result != NULL);
-      ASSERT (length == 11);
-      ASSERT (strcmp (result, "-3,1416e+09") == 0);
+      #if defined _WIN32 && !defined __CYGWIN__
+        /* Native Windows uses 3 digits for the exponent.  */
+        ASSERT (length == 12);
+        ASSERT (strcmp (result, "-3,1416e+009") == 0);
+      #else
+        ASSERT (length == 11);
+        ASSERT (strcmp (result, "-3,1416e+09") == 0);
+      #endif
       free (result);
     }
     {
index 3794d5f7c483582cd09c1ab0882796a7412ea2fe..4ccbe079aec5c6f2c3e513ee028ca1ea2f729cc5 100644 (file)
@@ -292,16 +292,28 @@ main (int argc, char *argv[])
       size_t length;
       wchar_t *result = asnwprintf (NULL, &length, L"%'.5g", 3141592653.5897932386);
       ASSERT (result != NULL);
-      ASSERT (length == 10);
-      ASSERT (wcscmp (result, L"3,1416e+09") == 0);
+      #if defined _WIN32 && !defined __CYGWIN__
+        /* Native Windows uses 3 digits for the exponent.  */
+        ASSERT (length == 11);
+        ASSERT (wcscmp (result, L"3,1416e+009") == 0);
+      #else
+        ASSERT (length == 10);
+        ASSERT (wcscmp (result, L"3,1416e+09") == 0);
+      #endif
       free (result);
     }
     {
       size_t length;
       wchar_t *result = asnwprintf (NULL, &length, L"%'.5g", -3141592653.5897932386);
       ASSERT (result != NULL);
-      ASSERT (length == 11);
-      ASSERT (wcscmp (result, L"-3,1416e+09") == 0);
+      #if defined _WIN32 && !defined __CYGWIN__
+        /* Native Windows uses 3 digits for the exponent.  */
+        ASSERT (length == 12);
+        ASSERT (wcscmp (result, L"-3,1416e+009") == 0);
+      #else
+        ASSERT (length == 11);
+        ASSERT (wcscmp (result, L"-3,1416e+09") == 0);
+      #endif
       free (result);
     }
     {