The attached patch adds support for using the POSIX getlocalename_l() function in illumos to avoid having to reach into undocumented/opaque structs.
This function was added to illumos in April 2025 in https://www.illumos.org/issues/17382 as part of the efforts to implement the requirements of POSIX 2024. I help maintain two different illumos distributions, OmniOS and Helios, and tested this patch on OmniOS r151054 with the results shown below. 2025-05-03 Andy Fiddaman <illu...@fiddaman.net> getlocalename_l-unsafe: Add support for the POSIX 2024 getlocalename_l on illumos to avoid reaching into undocumented structures. Thank you for considering this and please get in touch with any questions or if you need further information. Andy ## Testing % uname -a SunOS r151054 5.11 omnios-r151054-6ad70ba62c i86pc i386 i86pc % uname -o illumos % gcc -dM - -E< /dev/null | egrep 'sun|illumos' #define __sun 1 #define __illumos__ 1 #define sun 1 #define __sun__ 1 % ./configure checking build system type... x86_64-pc-solaris2.11 checking host system type... x86_64-pc-solaris2.11 checking for getlocalename_l... yes checking whether getlocalename_l is declared without a macro... yes checking whether getlocalename_l works... yes checking for uselocale... (cached) yes checking whether uselocale works... (cached) yes checking for Solaris 11.4 locale system... no checking for getlocalename_l... (cached) yes % grep HAVE_GETLOCALENAME_L config.h #define HAVE_GETLOCALENAME_L 1 % ./gltests/test-getlocalename_l % echo $? 0 % truss -u libc:getlocalename_l ./gltests/test-getlocalename_l ... /1: -> libc:getlocalename_l(0x5, 0xfffffc7fef021800) /1: <- libc:getlocalename_l() = 0xfffffc7fef020c00 /1: -> libc:getlocalename_l(0x4, 0xfffffc7fef021800) /1: <- libc:getlocalename_l() = 0xfffffc7fef020b00 /1: -> libc:getlocalename_l(0x1, 0xfffffc7fef021800) /1: <- libc:getlocalename_l() = 0xfffffc7fef020980 /1: -> libc:getlocalename_l(0x2, 0xfffffc7fef021800) /1: <- libc:getlocalename_l() = 0xfffffc7fef020a00 /1: _exit(0)
From 976a7c6f859a32fd81a876f5cf69c6430fe03f44 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman <illu...@fiddaman.net> Date: Sat, 3 May 2025 07:48:35 +0000 Subject: [PATCH] getlocalename_l-unsafe: Add support for the POSIX 2024 getlocalename_l on illumos to avoid reaching into undocumented structures. --- ChangeLog | 5 +++++ lib/getlocalename_l-unsafe.c | 8 ++++++-- m4/intl-thread-locale.m4 | 11 ++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c33aae4a7a..a081dab2e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-05-03 Andy Fiddaman <illu...@fiddaman.net> + + getlocalename_l-unsafe: Add support for the POSIX 2024 getlocalename_l + on illumos to avoid reaching into undocumented structures. + 2025-05-02 Collin Funk <collin.fu...@gmail.com> doc: Update documentation for 'open' errno discrepancies. diff --git a/lib/getlocalename_l-unsafe.c b/lib/getlocalename_l-unsafe.c index cb7ae5e5ea..bd12114684 100644 --- a/lib/getlocalename_l-unsafe.c +++ b/lib/getlocalename_l-unsafe.c @@ -38,7 +38,7 @@ # include <langinfo.h> #endif #if defined __sun -# if HAVE_SOLARIS114_LOCALES +# if HAVE_SOLARIS114_LOCALES && !HAVE_GETLOCALENAME_L # include <sys/localedef.h> # endif #endif @@ -528,7 +528,11 @@ getlocalename_l_unsafe (int category, locale_t locale) const char *name = ((struct _locale *) locale)->part_name[category]; return (struct string_with_storage) { name, STORAGE_OBJECT }; #elif defined __sun -# if HAVE_SOLARIS114_LOCALES +# if HAVE_GETLOCALENAME_L + /* illumos after April 2025 */ + const char *name = getlocalename_l (category, locale); + return (struct string_with_storage) { name, STORAGE_OBJECT }; +# elif HAVE_SOLARIS114_LOCALES /* Solaris >= 11.4. */ void *lcp = (*locale)->core.data->lcp; if (lcp != NULL) diff --git a/m4/intl-thread-locale.m4 b/m4/intl-thread-locale.m4 index 91a1c20896..e3ef5c8bbf 100644 --- a/m4/intl-thread-locale.m4 +++ b/m4/intl-thread-locale.m4 @@ -1,5 +1,5 @@ # intl-thread-locale.m4 -# serial 15 +# serial 16 dnl Copyright (C) 2015-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, @@ -127,6 +127,15 @@ int main () [Define if the locale_t type is as on Solaris 11.4.]) fi + dnl illumos supports the POSIX getlocalename_l as of April 2025. It can be + dnl used to improve the implementation of getlocalename_l_unsafe(), by + dnl removing the use of undocumented structures. + case "$gt_cv_func_uselocale_works" in + *yes) + AC_CHECK_FUNCS([getlocalename_l]) + ;; + esac + dnl This code is for platforms where the locale_t type does not provide access dnl to the name of each locale category. This code has the drawback that it dnl requires the gnulib overrides of 'newlocale', 'duplocale', 'freelocale', -- 2.49.0