]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
localename-environ: New module.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 01:02:58 +0000 (02:02 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 01:03:36 +0000 (02:03 +0100)
* 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.

ChangeLog
lib/localename-environ.c [new file with mode: 0644]
lib/localename-unsafe.c
m4/localename.m4
modules/localename-environ [new file with mode: 0644]
modules/localename-unsafe
modules/setlocale

index dd083951c524416ca4079b76693f4f2a41c3a228..6c4200a35fce052fa83059b683ed4c146a5fb992 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-02-14  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        locale-h: Ensure locale_t type.
diff --git a/lib/localename-environ.c b/lib/localename-environ.c
new file mode 100644 (file)
index 0000000..fea88fa
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "localename.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+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;
+}
index b3160b501560b03bbf0c67542cbcde22ba69c026..ebdf2e949190a60a3e6a3814fc8d3c26e1293cb3 100644 (file)
@@ -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)
 {
index ee614fd9430e15d08c1ba312b8da5e1a59881609..af94411b234f7261fadbe1876e4d4741beb38045 100644 (file)
@@ -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 (file)
index 0000000..dcfc47e
--- /dev/null
@@ -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
index b0aea3409dc036db97f1671ad99fa5432e5dfa2b..18fa5433bde400063b83237a50c56732468f8b28 100644 (file)
@@ -16,6 +16,7 @@ m4/musl.m4
 
 Depends-on:
 localename-unsafe-limited
+localename-environ
 extensions
 bool
 locale-h
index c59ca1f41e4ff8baea82aa3362d5cc32ce16d6b9..a7c52cdeef51b46e316c8a475c23483ce14786c9 100644 (file)
@@ -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