From be3d8140a0a1c3a1b4ec7b2ca2e931d7f0ef47fd Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 8 May 2022 19:17:30 -0400 Subject: load the locale lazily --- src/__main.c | 8 -------- src/locale/__get_locale.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/__main.c b/src/__main.c index 71a1c9e9..3e681799 100644 --- a/src/__main.c +++ b/src/__main.c @@ -4,12 +4,6 @@ #include "stdio/_stdio.h" #include "stdlib/_stdlib.h" -#ifdef _POSIX_SOURCE -#define DEFAULT_LOCALE "POSIX" -#else -#define DEFAULT_LOCALE "C" -#endif - void __main(int argc, char **argv) { extern int main(int, char*[]); @@ -35,8 +29,6 @@ void __main(int argc, char **argv) freopen(NULL, "w", stderr); setvbuf(stderr, NULL, _IONBF, 0); - setlocale(LC_ALL, DEFAULT_LOCALE); - exit(main(argc, argv)); } diff --git a/src/locale/__get_locale.c b/src/locale/__get_locale.c index 94bb62a0..b795d0f0 100644 --- a/src/locale/__get_locale.c +++ b/src/locale/__get_locale.c @@ -5,8 +5,19 @@ This implementation only supports a single, global locale. A second implementation will be needed for POSIX.1-2008 per-thread locales. */ +#ifdef _POSIX_SOURCE +# define DEFAULT_LOCALE "POSIX" +#else +# define DEFAULT_LOCALE "C" +#endif + struct __locale_t * __get_locale(void) { static struct __locale_t l; + static int loaded = 0; + if (!loaded) { + loaded = 1; + __load_locale(&l, LC_ALL, DEFAULT_LOCALE); + } return &l; } -- cgit v1.2.1