]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
setlocale: Use countof.
authorBruno Haible <bruno@clisp.org>
Mon, 11 May 2026 22:54:57 +0000 (00:54 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 11 May 2026 23:00:44 +0000 (01:00 +0200)
* lib/setlocale.c: Include <stdcountof.h>.
(setlocale_unixlike, get_main_locale_with_same_language,
get_main_locale_with_same_territory, setlocale_improved): Use countof.
* modules/setlocale (Depends-on): Add stdcountof-h.

ChangeLog
lib/setlocale.c
modules/setlocale

index 5e31f790bf906dc6ce306a6cf4556583823a693b..8bf96973037a78876dca1713d22b195df3407832 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-05-11  Bruno Haible  <bruno@clisp.org>
+
+       setlocale: Use countof.
+       * lib/setlocale.c: Include <stdcountof.h>.
+       (setlocale_unixlike, get_main_locale_with_same_language,
+       get_main_locale_with_same_territory, setlocale_improved): Use countof.
+       * modules/setlocale (Depends-on): Add stdcountof-h.
+
 2026-05-11  Bruno Haible  <bruno@clisp.org>
 
        gettext-h: Ensure no warnings with --disable-nls and -Wformat=2.
index 022105050ffa8407b7ac07378acebc11b514f39c..d40e1e2efdc6e9b3ab0c7fd9e9ffa6fd1863f1cc 100644 (file)
@@ -29,6 +29,7 @@
 /* Specification.  */
 #include <locale.h>
 
+#include <stdcountof.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -735,10 +736,7 @@ setlocale_unixlike (int category, const char *locale)
       {
         range_t range;
 
-        search (language_table,
-                sizeof (language_table) / sizeof (language_table[0]),
-                llCC_buf,
-                &range);
+        search (language_table, countof (language_table), llCC_buf, &range);
 
         for (size_t i = range.lo; i < range.hi; i++)
           {
@@ -782,17 +780,13 @@ setlocale_unixlike (int category, const char *locale)
                  and CC_buf in country_table.  */
               range_t language_range;
 
-              search (language_table,
-                      sizeof (language_table) / sizeof (language_table[0]),
-                      ll_buf,
+              search (language_table, countof (language_table), ll_buf,
                       &language_range);
               if (language_range.lo < language_range.hi)
                 {
                   range_t country_range;
 
-                  search (country_table,
-                          sizeof (country_table) / sizeof (country_table[0]),
-                          CC_buf,
+                  search (country_table, countof (country_table), CC_buf,
                           &country_range);
                   if (country_range.lo < country_range.hi)
                     for (size_t i = language_range.lo; i < language_range.hi; i++)
@@ -1162,7 +1156,7 @@ get_main_locale_with_same_language (const char *locale)
 {
 #   define table locales_with_principal_territory
   /* The table is sorted.  Perform a binary search.  */
-  size_t hi = sizeof (table) / sizeof (table[0]);
+  size_t hi = countof (table);
   size_t lo = 0;
   while (lo < hi)
     {
@@ -1391,7 +1385,7 @@ get_main_locale_with_same_territory (const char *locale)
     {
 #   define table locales_with_principal_language
       /* The table is sorted.  Perform a binary search.  */
-      size_t hi = sizeof (table) / sizeof (table[0]);
+      size_t hi = countof (table);
       size_t lo = 0;
       while (lo < hi)
         {
@@ -1483,7 +1477,7 @@ setlocale_improved (int category, const char *locale)
             goto fail;
 #  endif
 
-          for (; i < sizeof (categories) / sizeof (categories[0]); i++)
+          for (; i < countof (categories); i++)
             {
               int cat = categories[i];
               const char *name =
index 75c229738723040131a3e0593bf39b0a74d24634..aff365ac953d09ac59bd072ea0b6eae8392b1f6e 100644 (file)
@@ -7,6 +7,7 @@ m4/setlocale.m4
 
 Depends-on:
 locale-h
+stdcountof-h
 streq
 setlocale-fixes    [test $NEED_SETLOCALE_IMPROVED = 1]
 localename         [test $NEED_SETLOCALE_IMPROVED = 1]