From 5cf8af22900d359c18a75d9efed44f7c1d8fc06c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 22 Dec 2025 00:10:57 -0800 Subject: [PATCH] Simplify new %b/%B code many years from now * src/editfns.c (styled_format): Do %b and %B with sprintf if sprintf is known to support them. This will let us simplify this code many years from now. (Bug#79990) --- src/editfns.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/editfns.c b/src/editfns.c index 117722e0e09..0f2cf9fca1d 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -4029,7 +4029,19 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) } p[0] = negative ? '-' : plus_flag ? '+' : ' '; - if (conversion == 'b' || conversion == 'B') + + /* Do %b and %B by hand unless sprintf is known to + support them. Some day (the year 2043 perhaps?), + simplify this code by assuming that + HAVE_PRINTF_B_CONVERSION_SPECIFIER is true. */ +#if (202311 <= __STDC_VERSION_STDIO_H__ \ + || 2 < __GLIBC__ + (35 <= __GLIBC_MINOR__)) + enum { HAVE_PRINTF_B_CONVERSION_SPECIFIER = true }; +#else + enum { HAVE_PRINTF_B_CONVERSION_SPECIFIER = false }; +#endif + if (!HAVE_PRINTF_B_CONVERSION_SPECIFIER + && (conversion == 'b' || conversion == 'B')) { int bit_width = stdc_bit_width (x); char *bits = p + negative;