From 5af1f5942b2068d99182991dc212bdb3f5e9973d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 22 Oct 2018 00:22:33 -0400 Subject: make the default locale (& a variant) failure-free cases for newlocale commit aeeac9ca5490d7d90fe061ab72da446c01ddf746 introduced fail-safe invariants that creating a locale_t object for the C locale or C.UTF-8 locale will always succeed. extend the guarantee to also cover the following: - newlocale(LC_ALL_MASK, "", 0) - newlocale(LC_ALL_MASK-LC_CTYPE_MASK, "C", 0) provided that the LANG/LC_* environment variables have not been changed by the program. these usages are idiomatic for getting the default locale, and for getting a locale that behaves as the C locale except for honoring the default locale's character encoding. --- src/locale/newlocale.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/locale') diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c index 68574605..d20a8489 100644 --- a/src/locale/newlocale.c +++ b/src/locale/newlocale.c @@ -1,10 +1,22 @@ #include #include +#include #include "locale_impl.h" +static pthread_once_t default_locale_once; +static struct __locale_struct default_locale, default_ctype_locale; + +static void default_locale_init(void) +{ + for (int i=0; i