intl: Treat C.UTF-8 locale like C locale (BZ# 16621)

Message ID
State Under Review
Delegated to: Florian Weimer
Series intl: Treat C.UTF-8 locale like C locale (BZ# 16621) |


Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Bruno Haible Nov. 15, 2022, 12:56 a.m. UTC
  The wiki page
says that "Setting LC_ALL=C.UTF-8 will ignore LANGUAGE just like it
does with LC_ALL=C." This patch implements it.

* intl/dcigettext.c (guess_category_value): Treat C.<encoding> locale
like the C locale.
 intl/dcigettext.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)


diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index 1fc074a414..6a3c248e68 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -1564,8 +1564,12 @@  guess_category_value (int category, const char *categoryname)
      2. The precise output of some programs in the "C" locale is specified
 	by POSIX and should not depend on environment variables like
 	"LANGUAGE" or system-dependent information.  We allow such programs
-        to use gettext().  */
-  if (strcmp (locale, "C") == 0)
+        to use gettext().
+     Ignore LANGUAGE and its system-dependent analogon also if the locale is
+     set to "C.UTF-8" or, more generally, to "C.<encoding>", because that's
+     the by-design behaviour for glibc, see
+     <>.  */
+  if (locale[0] == 'C' && (locale[1] == '\0' || locale[1] == '.'))
     return locale;
   /* The highest priority value is the value of the 'LANGUAGE' environment