From: Bruno Haible Date: Fri, 14 Feb 2025 01:02:58 +0000 (+0100) Subject: localename-environ: New module. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3afa7cfedb4a621bcf4d4d48db3be76b9712c14;p=thirdparty%2Fgnulib.git localename-environ: New module. * lib/localename-environ.c: New file, extracted from lib/localename-unsafe.c. * lib/localename-unsafe.c (gl_locale_name_environ): Remove function. * m4/localename.m4 (gl_LOCALENAME_ENVIRON): New macro. * modules/localename-environ: New file. * modules/localename-unsafe (Depends-on): Add localename-environ. * modules/setlocale (Depends-on): Likewise. --- diff --git a/ChangeLog b/ChangeLog index dd083951c5..6c4200a35f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-02-14 Bruno Haible + + localename-environ: New module. + * lib/localename-environ.c: New file, extracted from + lib/localename-unsafe.c. + * lib/localename-unsafe.c (gl_locale_name_environ): Remove function. + * m4/localename.m4 (gl_LOCALENAME_ENVIRON): New macro. + * modules/localename-environ: New file. + * modules/localename-unsafe (Depends-on): Add localename-environ. + * modules/setlocale (Depends-on): Likewise. + 2025-02-13 Bruno Haible locale-h: Ensure locale_t type. diff --git a/lib/localename-environ.c b/lib/localename-environ.c new file mode 100644 index 0000000000..fea88fa88e --- /dev/null +++ b/lib/localename-environ.c @@ -0,0 +1,58 @@ +/* Determine name of the currently selected locale. + Copyright (C) 1995-2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Ulrich Drepper , 1995. */ + +#include + +/* Specification. */ +#include "localename.h" + +#include +#include + +const char * +gl_locale_name_environ (_GL_UNUSED int category, const char *categoryname) +{ + const char *retval; + + /* Setting of LC_ALL overrides all other. */ + retval = getenv ("LC_ALL"); + if (retval != NULL && retval[0] != '\0') + return retval; + /* Next comes the name of the desired category. */ + retval = getenv (categoryname); + if (retval != NULL && retval[0] != '\0') + return retval; + /* Last possibility is the LANG environment variable. */ + retval = getenv ("LANG"); + if (retval != NULL && retval[0] != '\0') + { +#if HAVE_CFPREFERENCESCOPYAPPVALUE + /* Mac OS X 10.2 or newer. + Ignore invalid LANG value set by the Terminal application. */ + if (strcmp (retval, "UTF-8") != 0) +#endif +#if defined __CYGWIN__ + /* Cygwin. + Ignore dummy LANG value set by ~/.profile. */ + if (strcmp (retval, "C.UTF-8") != 0) +#endif + return retval; + } + + return NULL; +} diff --git a/lib/localename-unsafe.c b/lib/localename-unsafe.c index b3160b5015..ebdf2e9491 100644 --- a/lib/localename-unsafe.c +++ b/lib/localename-unsafe.c @@ -3310,39 +3310,6 @@ gl_locale_name_posix_unsafe (int category, _GL_UNUSED const char *categoryname) } } -const char * -gl_locale_name_environ (_GL_UNUSED int category, const char *categoryname) -{ - const char *retval; - - /* Setting of LC_ALL overrides all other. */ - retval = getenv ("LC_ALL"); - if (retval != NULL && retval[0] != '\0') - return retval; - /* Next comes the name of the desired category. */ - retval = getenv (categoryname); - if (retval != NULL && retval[0] != '\0') - return retval; - /* Last possibility is the LANG environment variable. */ - retval = getenv ("LANG"); - if (retval != NULL && retval[0] != '\0') - { -#if HAVE_CFPREFERENCESCOPYAPPVALUE - /* Mac OS X 10.2 or newer. - Ignore invalid LANG value set by the Terminal application. */ - if (strcmp (retval, "UTF-8") != 0) -#endif -#if defined __CYGWIN__ - /* Cygwin. - Ignore dummy LANG value set by ~/.profile. */ - if (strcmp (retval, "C.UTF-8") != 0) -#endif - return retval; - } - - return NULL; -} - const char * gl_locale_name_default (void) { diff --git a/m4/localename.m4 b/m4/localename.m4 index ee614fd943..af94411b23 100644 --- a/m4/localename.m4 +++ b/m4/localename.m4 @@ -1,5 +1,5 @@ # localename.m4 -# serial 12 +# serial 13 dnl Copyright (C) 2007, 2009-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, @@ -61,3 +61,8 @@ AC_DEFUN([gl_LOCALENAME_UNSAFE_LIMITED], AC_REQUIRE([gt_LC_MESSAGES]) AC_REQUIRE([gt_INTL_THREAD_LOCALE_NAME]) ]) + +AC_DEFUN([gl_LOCALENAME_ENVIRON], +[ + AC_REQUIRE([gt_INTL_MACOSX]) +]) diff --git a/modules/localename-environ b/modules/localename-environ new file mode 100644 index 0000000000..dcfc47e468 --- /dev/null +++ b/modules/localename-environ @@ -0,0 +1,26 @@ +Description: +Return current locale's name, as specified by environment variables. + +Files: +lib/localename.h +lib/localename-environ.c +m4/localename.m4 +m4/intlmacosx.m4 + +Depends-on: + +configure.ac: +gl_LOCALENAME_ENVIRON +gl_LOCALE_MODULE_INDICATOR([localename-environ]) + +Makefile.am: +lib_SOURCES += localename-environ.c + +Include: +"localename.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/localename-unsafe b/modules/localename-unsafe index b0aea3409d..18fa5433bd 100644 --- a/modules/localename-unsafe +++ b/modules/localename-unsafe @@ -16,6 +16,7 @@ m4/musl.m4 Depends-on: localename-unsafe-limited +localename-environ extensions bool locale-h diff --git a/modules/setlocale b/modules/setlocale index c59ca1f41e..a7c52cdeef 100644 --- a/modules/setlocale +++ b/modules/setlocale @@ -7,8 +7,9 @@ m4/setlocale.m4 Depends-on: locale-h -localename [test $NEED_SETLOCALE_IMPROVED = 1] -setlocale-null [test $NEED_SETLOCALE_MTSAFE = 1] +localename [test $NEED_SETLOCALE_IMPROVED = 1] +localename-environ [test $NEED_SETLOCALE_IMPROVED = 1] +setlocale-null [test $NEED_SETLOCALE_MTSAFE = 1] configure.ac: gl_FUNC_SETLOCALE