Merge pull request #15651 from poettering/newlocale-check

check if locales are installed before using them
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-05-08 11:31:34 +02:00
committed by GitHub
7 changed files with 115 additions and 46 deletions
+15
View File
@@ -254,6 +254,21 @@ bool locale_is_valid(const char *name) {
return true;
}
int locale_is_installed(const char *name) {
if (!locale_is_valid(name))
return false;
if (STR_IN_SET(name, "C", "POSIX")) /* These ones are always OK */
return true;
_cleanup_(freelocalep) locale_t loc =
newlocale(LC_ALL_MASK, name, 0);
if (loc == (locale_t) 0)
return errno == ENOMEM ? -ENOMEM : false;
return true;
}
void init_gettext(void) {
setlocale(LC_ALL, "");
textdomain(GETTEXT_PACKAGE);
+1
View File
@@ -31,6 +31,7 @@ typedef enum LocaleVariable {
int get_locales(char ***l);
bool locale_is_valid(const char *name);
int locale_is_installed(const char *name);
#define _(String) gettext(String)
#define N_(String) String