Yesterday, Haiku introduced a getlocalename_l() function.
Here are two patches to deal with that:

1) There is a new test failure in test-getlocalename_l, because Haiku's
   function returns "POSIX" where Gnulib expects "C". Patch 0001 works
   around it.

2) Once this is done, the code in getlocalename_l-unsafe.c becomes relevant
   again. It contains a hack that is no longer needed now. Patch 0002 deals
   with that: it reduces the use of the hack to those Haiku versions that
   need it.


2026-01-08  Bruno Haible  <[email protected]>

        getlocalename_l-unsafe: Avoid hack on newer Haiku versions.
        * lib/getlocalename_l-unsafe.c (getlocalename_l_unsafe) [HAIKU]: Use the
        getlocalename_l function if available.

        getlocalename_l: Work around portability problem on Haiku.
        * m4/getlocalename_l.m4 (gl_FUNC_GETLOCALENAME_L_UNSAFE): Check against
        a Haiku problem.
        * doc/posix-functions/getlocalename_l.texi: Mention the Haiku problem.

>From 198c6c470adee27b72f3b6a9742400449e774a45 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 8 Jan 2026 14:01:32 +0100
Subject: [PATCH 1/2] getlocalename_l: Work around portability problem on
 Haiku.

* m4/getlocalename_l.m4 (gl_FUNC_GETLOCALENAME_L_UNSAFE): Check against
a Haiku problem.
* doc/posix-functions/getlocalename_l.texi: Mention the Haiku problem.
---
 ChangeLog                                |  7 +++++++
 doc/posix-functions/getlocalename_l.texi |  3 +++
 m4/getlocalename_l.m4                    | 23 ++++++++++++++++++++---
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9879b37d90..1d3b74bc78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-01-08  Bruno Haible  <[email protected]>
+
+	getlocalename_l: Work around portability problem on Haiku.
+	* m4/getlocalename_l.m4 (gl_FUNC_GETLOCALENAME_L_UNSAFE): Check against
+	a Haiku problem.
+	* doc/posix-functions/getlocalename_l.texi: Mention the Haiku problem.
+
 2026-01-07  Bruno Haible  <[email protected]>
 
 	getdelim: Avoid a -Wjump-misses-init warning (regr. 2025-12-09).
diff --git a/doc/posix-functions/getlocalename_l.texi b/doc/posix-functions/getlocalename_l.texi
index 68c0518da4..ac73a89d73 100644
--- a/doc/posix-functions/getlocalename_l.texi
+++ b/doc/posix-functions/getlocalename_l.texi
@@ -20,6 +20,9 @@
 on some platforms:
 @c https://cygwin.com/pipermail/cygwin/2025-March/257715.html
 Cygwin 3.6.0.
+@item
+This function returns @code{"POSIX"} instead of @code{"C"} onn some platforms:
+Haiku.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/getlocalename_l.m4 b/m4/getlocalename_l.m4
index d478e3c36f..12ccb2dc35 100644
--- a/m4/getlocalename_l.m4
+++ b/m4/getlocalename_l.m4
@@ -1,5 +1,5 @@
 # getlocalename_l.m4
-# serial 4
+# serial 5
 dnl Copyright (C) 2025-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,
@@ -30,6 +30,8 @@ AC_DEFUN_ONCE([gl_FUNC_GETLOCALENAME_L_UNSAFE]
   if test $ac_cv_func_getlocalename_l = yes; then
     dnl Check against the Cygwin 3.6.0 bug: It returns an invalid pointer when
     dnl the second argument is LC_GLOBAL_LOCALE.
+    dnl Check against a Haiku >= hrev59293 oddity: It returns "POSIX" instead
+    dnl of "C". We prefer "C".
     AC_REQUIRE([AC_CANONICAL_HOST])
     AC_CACHE_CHECK([whether getlocalename_l works],
       [gl_cv_func_getlocalename_l_works],
@@ -39,14 +41,29 @@ AC_DEFUN_ONCE([gl_FUNC_GETLOCALENAME_L_UNSAFE]
 #include <string.h>
 int main ()
 {
-  const char *ret = getlocalename_l (LC_COLLATE, LC_GLOBAL_LOCALE);
-  return strlen (ret) == 0;
+  int result = 0;
+  /* Check againt the Cygwin bug.  */
+  {
+    const char *ret = getlocalename_l (LC_COLLATE, LC_GLOBAL_LOCALE);
+    if (strlen (ret) == 0)
+      result |= 1;
+  }
+  /* Check against the Haiku oddity.  */
+  {
+    const char *ret =
+      getlocalename_l (LC_COLLATE, newlocale (LC_ALL_MASK, "C", NULL));
+    if (strcmp (ret, "C") != 0)
+      result |= 2;
+  }
+  return result;
 }]])],
          [gl_cv_func_getlocalename_l_works=yes],
          [gl_cv_func_getlocalename_l_works=no],
          [case "$host_os" in
             cygwin*) # Guess no on Cygwin.
               gl_cv_func_getlocalename_l_works="guessing no" ;;
+            haiku*)  # Guess no on Haiku.
+              gl_cv_func_getlocalename_l_works="guessing no" ;;
             *)       # Guess yes otherwise.
               gl_cv_func_getlocalename_l_works="guessing yes" ;;
           esac
-- 
2.52.0

>From f93345147656a7a39462a00d14e154dc8d1dfa34 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 8 Jan 2026 14:15:40 +0100
Subject: [PATCH 2/2] getlocalename_l-unsafe: Avoid hack on newer Haiku
 versions.

* lib/getlocalename_l-unsafe.c (getlocalename_l_unsafe) [HAIKU]: Use the
getlocalename_l function if available.
---
 ChangeLog                    |  4 ++++
 lib/getlocalename_l-unsafe.c | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 1d3b74bc78..271db843f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2026-01-08  Bruno Haible  <[email protected]>
 
+	getlocalename_l-unsafe: Avoid hack on newer Haiku versions.
+	* lib/getlocalename_l-unsafe.c (getlocalename_l_unsafe) [HAIKU]: Use the
+	getlocalename_l function if available.
+
 	getlocalename_l: Work around portability problem on Haiku.
 	* m4/getlocalename_l.m4 (gl_FUNC_GETLOCALENAME_L_UNSAFE): Check against
 	a Haiku problem.
diff --git a/lib/getlocalename_l-unsafe.c b/lib/getlocalename_l-unsafe.c
index 12a81c1f5f..665e6d62fa 100644
--- a/lib/getlocalename_l-unsafe.c
+++ b/lib/getlocalename_l-unsafe.c
@@ -579,6 +579,15 @@ getlocalename_l_unsafe (int category, locale_t locale)
 # endif
       return (struct string_with_storage) { name, STORAGE_OBJECT };
 #elif defined __HAIKU__
+# if HAVE_GETLOCALENAME_L
+      /* Haiku revision hrev59293 (2026-01-07) or newer.  */
+#  undef getlocalename_l
+      const char *name = getlocalename_l (category, locale);
+      if (strcmp (name, "POSIX") != 0)
+        return (struct string_with_storage) { name, STORAGE_OBJECT };
+      else
+        return (struct string_with_storage) { "C", STORAGE_INDEFINITE };
+# else
       /* Since 2022, Haiku has per-thread locales.  locale_t is 'void *',
          but in fact a 'LocaleBackendData *'.  */
       struct LocaleBackendData {
@@ -641,6 +650,7 @@ getlocalename_l_unsafe (int category, locale_t locale)
       else
         /* It's the "C" or "POSIX" locale.  */
         return (struct string_with_storage) { "C", STORAGE_INDEFINITE };
+# endif
 #elif defined __ANDROID__
       /* Android API level >= 21 */
       struct __locale_t {
-- 
2.52.0

Reply via email to