From: Yu Watanabe Date: Tue, 11 Nov 2025 22:30:01 +0000 (+0900) Subject: musl: locale-util: explicitly check existence of locale file X-Git-Tag: v259-rc1~88^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=361beb82a5ff6580c63f1e6fa4999ae6ff8772ed;p=thirdparty%2Fsystemd.git musl: locale-util: explicitly check existence of locale file musl's newlocale() always provides a locale object even the requested locale does not exist. Let's explicitly check the existence of the requested locale file. --- diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 36fe153379f..ebccc6a8bd5 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "dirent-util.h" #include "env-util.h" @@ -299,11 +300,25 @@ int locale_is_installed(const char *name) { if (STR_IN_SET(name, "C", "POSIX")) /* These ones are always OK */ return true; +#ifdef __GLIBC__ _cleanup_(freelocalep) locale_t loc = newlocale(LC_ALL_MASK, name, (locale_t) 0); if (loc == (locale_t) 0) return errno == ENOMEM ? -ENOMEM : false; return true; +#else + /* musl also has C.UTF-8 as builtin */ + if (streq(name, "C.UTF-8")) + return true; + + /* musl's newlocale() always succeeds and provides a fake locale object even when the locale does + * not exist. Hence, we need to explicitly check if the locale file exists. */ + _cleanup_free_ char *p = path_join("/usr/share/i18n/locales/musl/", name); + if (!p) + return -ENOMEM; + + return access(p, F_OK) >= 0; +#endif } static bool is_locale_utf8_impl(void) {