Paul Eggert wrote:
> Thanks for mentioning that. I installed the attached to try to fix this.

Thanks. Two nits:
  * Before using the MUSL_LIBC symbol, one needs to AC_REQUIRE([gl_MUSL_LIBC]).
  * Haiku is also such a system.
    - musl libc                         is mentioned in tests/test-isalnum_l.c.
    - macOS, BeOS, Haiku                are mentioned in lib/localcharset.c.
    - Android                           is mentioned in tests/test-mbrtowc.c.


2026-05-26  Bruno Haible  <[email protected]>

        quotearg: Improve USE_C_LOCALE code on Haiku.
        * lib/quotearg.c (C_LOCALE_MIGHT_BE_MULTIBYTE): Define also on Haiku.
        Add comments.

2026-05-26  Bruno Haible  <[email protected]>

        quotearg: Improve USE_C_LOCALE code on musl libc.
        * m4/quotearg.m4 (gl_QUOTEARG): Require gl_MUSL_LIBC.
        * modules/quotearg (Files): Add m4/musl.m4.

>From 5df012a1fba96e05f1697fc35e1a6c9706ae8f43 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Tue, 26 May 2026 19:40:43 +0200
Subject: [PATCH 1/2] quotearg: Improve USE_C_LOCALE code on musl libc.

* m4/quotearg.m4 (gl_QUOTEARG): Require gl_MUSL_LIBC.
* modules/quotearg (Files): Add m4/musl.m4.
---
 ChangeLog        | 6 ++++++
 m4/quotearg.m4   | 3 ++-
 modules/quotearg | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 33a67ff322..c488cbddba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-05-26  Bruno Haible  <[email protected]>
+
+	quotearg: Improve USE_C_LOCALE code on musl libc.
+	* m4/quotearg.m4 (gl_QUOTEARG): Require gl_MUSL_LIBC.
+	* modules/quotearg (Files): Add m4/musl.m4.
+
 2026-05-25  Paul Eggert  <[email protected]>
 
 	xalloc-oversized: pacify gcc -Wuseless-cast
diff --git a/m4/quotearg.m4 b/m4/quotearg.m4
index 330743b3bf..ceca5925ad 100644
--- a/m4/quotearg.m4
+++ b/m4/quotearg.m4
@@ -1,5 +1,5 @@
 # quotearg.m4
-# serial 10
+# serial 11
 dnl Copyright (C) 2002, 2004-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,5 +9,6 @@
 AC_DEFUN([gl_QUOTEARG],
 [
   AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_MUSL_LIBC])
   :
 ])
diff --git a/modules/quotearg b/modules/quotearg
index 17a7c1314c..7e61400ef1 100644
--- a/modules/quotearg
+++ b/modules/quotearg
@@ -6,6 +6,7 @@ lib/quotearg.h
 lib/quotearg.c
 lib/quote.h
 m4/quotearg.m4
+m4/musl.m4
 
 Depends-on:
 attribute
-- 
2.54.0

From b08d71c27dc04eb6281dd6361b2d4c167c672c01 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Tue, 26 May 2026 19:49:09 +0200
Subject: [PATCH 2/2] quotearg: Improve USE_C_LOCALE code on Haiku.

* lib/quotearg.c (C_LOCALE_MIGHT_BE_MULTIBYTE): Define also on Haiku.
Add comments.
---
 ChangeLog      |  6 ++++++
 lib/quotearg.c | 14 ++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c488cbddba..6931087b53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-05-26  Bruno Haible  <[email protected]>
+
+	quotearg: Improve USE_C_LOCALE code on Haiku.
+	* lib/quotearg.c (C_LOCALE_MIGHT_BE_MULTIBYTE): Define also on Haiku.
+	Add comments.
+
 2026-05-26  Bruno Haible  <[email protected]>
 
 	quotearg: Improve USE_C_LOCALE code on musl libc.
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 3c2bf946ed..1c31a1ec04 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -49,10 +49,16 @@
 # define USE_C_LOCALE 0
 #endif
 
-/* On recent-enough Android, Darwin/iOS/macOS and musl,
-   the "C" locale uses UTF-8, contrary to POSIX.  */
-#if (defined __ANDROID__ || (defined __APPLE__ && defined __MACH__) \
-     || defined MUSL_LIBC)
+/* On several platforms, the default locale uses UTF-8, contrary to POSIX:
+   - musl libc has no unibyte locales; the "C" locale uses UTF-8.
+   - On macOS, all modern locales use the UTF-8 encoding.
+   - BeOS and Haiku have a single locale, and it has UTF-8 encoding.
+   - On Android ??? 5.0, the default locale is the "C.UTF-8" locale, not the
+     "C" locale.  Furthermore, when you attempt to set the "C" or "POSIX"
+     locale via setlocale(), what you get is a "C" locale with UTF-8 encoding,
+     that is, effectively the "C.UTF-8" locale.  */
+#if (defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) \
+     || defined __BEOS__ || defined __HAIKU__ || defined __ANDROID__)
 # define C_LOCALE_MIGHT_BE_MULTIBYTE true
 #else
 # define C_LOCALE_MIGHT_BE_MULTIBYTE false
-- 
2.54.0

Reply via email to