From 7185cb33c78271c22a852540fcd81f5111eb4933 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 1 Aug 2015 14:36:13 +0200 Subject: [PATCH] Remove setlocale thread safety. This interface isn't standardized to be thread safe so nobody can rely on it. Additionally this only thread secures setlocale, but not all the code that might depend on the current locale, so it is pointless. --- libc/include/locale.h | 7 +------ libc/locale/setlocale.cpp | 22 ++++++---------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/libc/include/locale.h b/libc/include/locale.h index eb9573fa..c17457ae 100644 --- a/libc/include/locale.h +++ b/libc/include/locale.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2012. + Copyright(C) Jonas 'Sortie' Termansen 2012, 2015. This file is part of the Sortix C Library. @@ -70,12 +70,7 @@ struct lconv #define LC_ALL 6 #define LC_NUM_CATEGORIES LC_ALL -const char* sortix_setlocale(int category, const char* locale); -#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS -const char* setlocale(int category, const char* locale) __asm__ ("sortix_setlocale"); -#else char* setlocale(int category, const char* locale); -#endif struct lconv* localeconv(void); #ifdef __cplusplus diff --git a/libc/locale/setlocale.cpp b/libc/locale/setlocale.cpp index 4d6b99b9..e5a19619 100644 --- a/libc/locale/setlocale.cpp +++ b/libc/locale/setlocale.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2012, 2014. + Copyright(C) Jonas 'Sortie' Termansen 2012, 2014, 2015. This file is part of the Sortix C Library. @@ -22,45 +22,35 @@ *******************************************************************************/ -#define __SORTIX_STDLIB_REDIRECTS 0 #include #include -#include #include #include -static pthread_mutex_t locale_lock = PTHREAD_MUTEX_INITIALIZER; static char* current_locales[LC_NUM_CATEGORIES] = { NULL }; -extern "C" const char* sortix_setlocale(int category, const char* locale) +extern "C" char* setlocale(int category, const char* locale) { if ( category < 0 || LC_ALL < category ) - return errno = EINVAL, (const char*) NULL; + return errno = EINVAL, (char*) NULL; char* new_strings[LC_NUM_CATEGORIES]; int from = category != LC_ALL ? category : 0; int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1; if ( !locale ) - return current_locales[to] ? current_locales[to] : "C"; + return current_locales[to] ? current_locales[to] : (char*) "C"; for ( int i = from; i <= to; i++ ) { if ( !(new_strings[i] = strdup(locale)) ) { for ( int n = from; n < i; n++ ) free(new_strings[n]); - return NULL; + return (char*) NULL; } } - pthread_mutex_lock(&locale_lock); for ( int i = from; i <= to; i++ ) { free(current_locales[i]); current_locales[i] = new_strings[i]; } - pthread_mutex_unlock(&locale_lock); - return locale; -} - -extern "C" char* setlocale(int category, const char* locale) -{ - return (char*) sortix_setlocale(category, locale); + return (char*) locale; }