From a625dfa4f2456b1a866489e5be15fb46578237a5 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 27 Apr 2018 10:00:52 +0200 Subject: library: Use dedicated locale object for printing error --- common/library.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'common/library.c') diff --git a/common/library.c b/common/library.c index 37cb1c8..52c3347 100644 --- a/common/library.c +++ b/common/library.c @@ -44,6 +44,9 @@ #include "message.h" #include +#ifdef HAVE_LOCALE_H +#include +#endif #include #include #include @@ -67,6 +70,10 @@ pthread_once_t p11_library_once = PTHREAD_ONCE_INIT; unsigned int p11_forkid = 1; +#ifdef HAVE_LOCALE_H +extern locale_t p11_message_locale; +#endif + static char * thread_local_message (void) { @@ -123,6 +130,9 @@ p11_library_init_impl (void) p11_mutex_init (&p11_virtual_mutex); pthread_key_create (&thread_local, free); p11_message_storage = thread_local_message; +#ifdef HAVE_NEWLOCALE + p11_message_locale = newlocale (LC_ALL_MASK, "POSIX", (locale_t) 0); +#endif pthread_atfork (NULL, NULL, count_forks); } @@ -142,6 +152,9 @@ p11_library_uninit (void) free (pthread_getspecific (thread_local)); pthread_setspecific (thread_local, NULL); +#ifdef HAVE_NEWLOCALE + freelocale (p11_message_locale); +#endif p11_message_storage = dont_store_message; pthread_key_delete (thread_local); p11_mutex_uninit (&p11_virtual_mutex); -- cgit v1.1