1 // -*- C++ -*- 2 //===-------------------- support/win32/locale_win32.cpp ------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #include "support/win32/locale_win32.h" 12 13 #include <stdarg.h> // va_start, va_end 14 15 // FIXME: base currently unused. Needs manual work to construct the new locale 16 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ ) 17 { 18 return _create_locale( mask, locale ); 19 } 20 locale_t uselocale( locale_t newloc ) 21 { 22 locale_t old_locale = _get_current_locale(); 23 // uselocale sets the thread's locale by definition, so unconditionally use thread-local locale 24 _configthreadlocale( _ENABLE_PER_THREAD_LOCALE ); 25 // uselocale sets all categories 26 setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale ); 27 // uselocale returns the old locale_t 28 return old_locale; 29 } 30 lconv *localeconv_l( locale_t loc ) 31 { 32 __locale_raii __current( uselocale(loc), uselocale ); 33 return localeconv(); 34 } 35 size_t mbrlen_l( const char *__restrict__ s, size_t n, 36 mbstate_t *__restrict__ ps, locale_t loc ) 37 { 38 __locale_raii __current( uselocale(loc), uselocale ); 39 return mbrlen( s, n, ps ); 40 } 41 size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src, 42 size_t len, mbstate_t *__restrict__ ps, locale_t loc ) 43 { 44 __locale_raii __current( uselocale(loc), uselocale ); 45 return mbsrtowcs( dst, src, len, ps ); 46 } 47 size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps, 48 locale_t loc ) 49 { 50 __locale_raii __current( uselocale(loc), uselocale ); 51 return wcrtomb( s, wc, ps ); 52 } 53 size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s, 54 size_t n, mbstate_t *__restrict__ ps, locale_t loc ) 55 { 56 __locale_raii __current( uselocale(loc), uselocale ); 57 return mbrtowc( pwc, s, n, ps ); 58 } 59 size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src, 60 size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc ) 61 { 62 __locale_raii __current( uselocale(loc), uselocale ); 63 return mbsnrtowcs( dst, src, nms, len, ps ); 64 } 65 size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src, 66 size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc ) 67 { 68 __locale_raii __current( uselocale(loc), uselocale ); 69 return wcsnrtombs( dst, src, nwc, len, ps ); 70 } 71 wint_t btowc_l( int c, locale_t loc ) 72 { 73 __locale_raii __current( uselocale(loc), uselocale ); 74 return btowc( c ); 75 } 76 int wctob_l( wint_t c, locale_t loc ) 77 { 78 __locale_raii __current( uselocale(loc), uselocale ); 79 return wctob( c ); 80 } 81 82 int asprintf_l( char **ret, locale_t loc, const char *format, ... ) 83 { 84 va_list ap; 85 va_start( ap, format ); 86 int result = vasprintf_l( ret, loc, format, ap ); 87 va_end(ap); 88 return result; 89 } 90 int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ) 91 { 92 __locale_raii __current( uselocale(loc), uselocale ); 93 return vasprintf( ret, format, ap ); 94 } 95