cmp: improve LC_MESSAGES test

* src/cmp.c (hard_locale_LC_MESSAGES): Use setlocale, not gettext,
to decide whether the messages might not be those of the C or
POSIX locale.  This is a more reliable way to test whether
the locale is something like en_US.utf8, a locale that does
not have a translation catalog but is not the C locale.
This commit is contained in:
Paul Eggert 2025-09-09 09:16:16 -07:00
parent cf5648869a
commit dc6dc9147f

View File

@ -45,12 +45,15 @@ static char const PROGRAM_NAME[] = "cmp";
proper_name_lite ("Torbjorn Granlund", "Torbj\303\266rn Granlund"), \
_("David MacKenzie")
/* Return true if the locale's messages might not be those of C or POSIX. */
static bool
hard_locale_LC_MESSAGES (void)
{
#if defined LC_MESSAGES && ENABLE_NLS
static char const copyright_string[] = "(C)";
return gettext (copyright_string) != copyright_string;
#if ENABLE_NLS
/* GNU diff defines ENABLE_NLS only if gettext is preinstalled, and
on these platforms setlocale (LC_MESSAGES, nullptr) never returns nullptr
and always returns "C" when in the C or POSIX locales. */
return !STREQ (setlocale (LC_MESSAGES, nullptr), "C");
#else
return false;
#endif