]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Update after gnulib changed.
authorBruno Haible <bruno@clisp.org>
Wed, 24 Jun 2026 20:51:38 +0000 (22:51 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 25 Jun 2026 03:34:59 +0000 (05:34 +0200)
* gettext-runtime/intl/libgnuintl.in.h (libintl_setlocale): Change the return
type to 'const char *'.
(setlocale): Change the return type to 'const char *' if possible without
causing a conflict with <locale.h>.
* gettext-runtime/intl/setlocale.c (setlocale_unixlike): Change the return type
to 'const char *'. Remove a cast.
(setlocale_single): Change the return type to 'const char *'.
(libintl_setlocale): Change the return type to 'const char *'. Change three
variables from 'char *' to 'const char *'. Add local variable old_locale.

gettext-runtime/intl/libgnuintl.in.h
gettext-runtime/intl/setlocale.c

index c326df2fcce229895b680aa297f1676fd11fd714..237e8d1256999f853dc105aa3ac0079e27270aba 100644 (file)
@@ -1081,8 +1081,11 @@ namespace std { using ::libintl_freelocale; }
 #if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__
 
 # ifndef GNULIB_defined_setlocale /* don't override gnulib */
+/* The return type 'const char *' serves the purpose of producing warnings
+   for invalid uses of the value returned from this function.  */
 #  ifdef _INTL_REDIRECT_INLINE
-extern char *libintl_setlocale (int, const char *);
+extern const char *libintl_setlocale (int, const char *);
+#   undef setlocale /* Disable #define setlocale(...) ... */
 #   ifndef __cplusplus
 static
 #   endif
@@ -1090,15 +1093,22 @@ inline
 _INTL_FORCE_INLINE
 char *setlocale (int __category, const char *__locale)
 {
-  return libintl_setlocale (__category, __locale);
+#   ifdef __cplusplus
+  return const_cast<char *>(libintl_setlocale (__category, __locale));
+#   else
+  return (char *) libintl_setlocale (__category, __locale);
+#   endif
 }
 #  elif !defined _INTL_NO_DEFINE_MACRO_SETLOCALE
 #   ifdef _INTL_REDIRECT_MACROS
 #    undef setlocale
 #    define setlocale libintl_setlocale
-#   endif
+extern const char *setlocale (int, const char *);
+#   else /* defined _INTL_REDIRECT_ASM */
+#    undef setlocale /* Disable #define setlocale(...) ... */
 extern char *setlocale (int, const char *)
        _INTL_ASM (libintl_setlocale);
+#   endif
 #   if defined _INTL_REDIRECT_MACROS && defined __cplusplus && !defined _INTL_CXX_NO_CLOBBER_STD_NAMESPACE
 namespace std { using ::libintl_setlocale; }
 #   endif
index 8f7c394f6ae582e93fb57d29c2575ae6d0ad106b..c5265082984fb6e16569ea7d693fc5f9ef695247 100644 (file)
@@ -666,7 +666,7 @@ search (const struct table_entry *table, size_t table_size, const char *string,
 
 /* Like setlocale, but accept also locale names in the form ll or ll_CC,
    where ll is an ISO 639 language code and CC is an ISO 3166 country code.  */
-static char *
+static const char *
 setlocale_unixlike (int category, const char *locale)
 {
   int is_utf8 = (GetACP () == 65001);
@@ -686,7 +686,7 @@ setlocale_unixlike (int category, const char *locale)
     locale = "English_United States.65001";
 
   /* First, try setlocale with the original argument unchanged.  */
-  char *result = setlocale (category, locale);
+  const char *result = setlocale (category, locale);
   if (result != NULL)
     return result;
 
@@ -843,10 +843,10 @@ setlocale_unixlike (int category, const char *locale)
 # elif defined __ANDROID__
 
 /* Like setlocale, but accept also the locale names "C" and "POSIX".  */
-static char *
+static const char *
 setlocale_unixlike (int category, const char *locale)
 {
-  char *result = setlocale_fixed (category, locale);
+  const char *result = setlocale_fixed (category, locale);
   if (result == NULL)
     switch (category)
       {
@@ -864,7 +864,7 @@ setlocale_unixlike (int category, const char *locale)
       case LC_MEASUREMENT:
         if (locale == NULL
             || streq (locale, "C") || streq (locale, "POSIX"))
-          result = (char *) "C";
+          result = "C";
         break;
       default:
         break;
@@ -880,7 +880,7 @@ setlocale_unixlike (int category, const char *locale)
 # if LC_MESSAGES == 1729
 
 /* Like setlocale, but support also LC_MESSAGES.  */
-static char *
+static const char *
 setlocale_single (int category, const char *locale)
 {
   if (category == LC_MESSAGES)
@@ -1416,7 +1416,7 @@ get_main_locale_with_same_territory (const char *locale)
 # endif
 
 SHLIB_EXPORTED
-char *
+const char *
 libintl_setlocale (int category, const char *locale)
 {
   if (locale != NULL && locale[0] == '\0')
@@ -1436,10 +1436,10 @@ libintl_setlocale (int category, const char *locale)
             };
 
           /* Back up the old locale, in case one of the steps fails.  */
-          char *saved_locale = setlocale (LC_ALL, NULL);
-          if (saved_locale == NULL)
+          const char *old_locale = setlocale (LC_ALL, NULL);
+          if (old_locale == NULL)
             return NULL;
-          saved_locale = strdup (saved_locale);
+          char *saved_locale = strdup (old_locale);
           if (saved_locale == NULL)
             return NULL;
 
@@ -1676,18 +1676,16 @@ libintl_setlocale (int category, const char *locale)
               /* In the underlying implementation, LC_ALL does not contain
                  LC_MESSAGES.  Therefore we need to handle LC_MESSAGES
                  separately.  */
-              char *result;
+              const char *result;
 
 #  if defined _WIN32 && ! defined __CYGWIN__
               if (strchr (native_locale, '.') != NULL)
                 {
-                  char *saved_locale;
-
                   /* Back up the old locale.  */
-                  saved_locale = setlocale (LC_ALL, NULL);
-                  if (saved_locale == NULL)
+                  const char *old_locale = setlocale (LC_ALL, NULL);
+                  if (old_locale == NULL)
                     return NULL;
-                  saved_locale = strdup (saved_locale);
+                  char *saved_locale = strdup (old_locale);
                   if (saved_locale == NULL)
                     return NULL;
 
@@ -1757,8 +1755,8 @@ libintl_setlocale (int category, const char *locale)
      "LC_COLLATE=...;LC_CTYPE=...;LC_MONETARY=...;LC_NUMERIC=...;LC_TIME=..."
      If necessary, add ";LC_MESSAGES=..." at the end.  */
   {
-    char *name1 = setlocale (LC_ALL, NULL);
-    char *name2 = setlocale_single (LC_MESSAGES, NULL);
+    const char *name1 = setlocale (LC_ALL, NULL);
+    const char *name2 = setlocale_single (LC_MESSAGES, NULL);
     if (streq (name1, name2))
       /* Not a mixed locale.  */
       return name1;