From: Yu Watanabe Date: Tue, 11 Nov 2025 22:27:50 +0000 (+0900) Subject: musl: locale-util: introduce musl specific locale enumerator X-Git-Tag: v259-rc1~88^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b2a2f670aec83e83a8798cf901950cb1ae63b54d;p=thirdparty%2Fsystemd.git musl: locale-util: introduce musl specific locale enumerator Both add_locales_from_archive() and add_locales_from_libdir() are glibc specific, and the logic cannot be applied when built with musl. --- diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 455b54bc61c..36fe153379f 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -54,6 +54,7 @@ static char* normalize_locale(const char *name) { return strdup(name); } +#ifdef __GLIBC__ static int add_locales_from_archive(Set *locales) { /* Stolen from glibc... */ @@ -182,6 +183,34 @@ static int add_locales_from_libdir(Set *locales) { return 0; } +#else + +static int add_locales_for_musl(Set *locales) { + int r; + + assert(locales); + + _cleanup_closedir_ DIR *dir = opendir("/usr/share/i18n/locales/musl/"); + if (!dir) + return errno == ENOENT ? 0 : -errno; + + FOREACH_DIRENT(de, dir, return -errno) { + if (de->d_type != DT_REG) + continue; + + char *z = normalize_locale(de->d_name); + if (!z) + return -ENOMEM; + + r = set_consume(locales, z); + if (r < 0) + return r; + } + + return 0; +} +#endif + int get_locales(char ***ret) { _cleanup_set_free_ Set *locales = NULL; int r; @@ -190,6 +219,7 @@ int get_locales(char ***ret) { if (!locales) return -ENOMEM; +#ifdef __GLIBC__ r = add_locales_from_archive(locales); if (r < 0 && r != -ENOENT) return r; @@ -197,6 +227,11 @@ int get_locales(char ***ret) { r = add_locales_from_libdir(locales); if (r < 0) return r; +#else + r = add_locales_for_musl(locales); + if (r < 0) + return r; +#endif char *locale; SET_FOREACH(locale, locales) {