From dd34d89b668254aa8b05192d396ab9f3069a0c28 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 22 Jul 2022 11:09:15 +0200 Subject: util: Add locale verification function Same as the XPG locale verification, but also considers empty strings as valid locale, as this means "use the system value" in AccountsService. --- src/util.c | 8 ++++++++ src/util.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/util.c b/src/util.c index 3b7a2da..54cdd6d 100644 --- a/src/util.c +++ b/src/util.c @@ -389,3 +389,11 @@ verify_xpg_locale (const char *locale) { return (explode_locale (locale, NULL, NULL, NULL, NULL) & COMPONENT_LANGUAGE); } + +gboolean +verify_locale (const char *locale) +{ + if (locale && *locale == '\0') + return TRUE; + return verify_xpg_locale (locale); +} diff --git a/src/util.h b/src/util.h index c51887e..a42d0ed 100644 --- a/src/util.h +++ b/src/util.h @@ -44,6 +44,7 @@ gint get_user_groups (const gchar *username, gid_t **groups); gboolean verify_xpg_locale (const char *locale); +gboolean verify_locale (const char *locale); G_END_DECLS -- cgit v1.2.1