Home | History | Annotate | Download | only in win32
      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 <locale>
     12 #include <cstdarg> // va_start, va_end
     13 #include <memory>
     14 #include <type_traits>
     15 
     16 int __libcpp_vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
     17 
     18 using std::__libcpp_locale_guard;
     19 
     20 // FIXME: base currently unused. Needs manual work to construct the new locale
     21 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
     22 {
     23     return {_create_locale( LC_ALL, locale ), locale};
     24 }
     25 
     26 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
     27 {
     28 #if defined(_LIBCPP_MSVCRT)
     29   return ___mb_cur_max_l_func(__l);
     30 #else
     31   __libcpp_locale_guard __current(__l);
     32   return MB_CUR_MAX;
     33 #endif
     34 }
     35 
     36 
     37 lconv *localeconv_l( locale_t loc )
     38 {
     39     __libcpp_locale_guard __current(loc);
     40     return localeconv();
     41 }
     42 size_t mbrlen_l( const char *__restrict s, size_t n,
     43                  mbstate_t *__restrict ps, locale_t loc )
     44 {
     45     __libcpp_locale_guard __current(loc);
     46     return mbrlen( s, n, ps );
     47 }
     48 size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
     49                     size_t len, mbstate_t *__restrict ps, locale_t loc )
     50 {
     51     __libcpp_locale_guard __current(loc);
     52     return mbsrtowcs( dst, src, len, ps );
     53 }
     54 size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
     55                   locale_t loc )
     56 {
     57     __libcpp_locale_guard __current(loc);
     58     return wcrtomb( s, wc, ps );
     59 }
     60 size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
     61                   size_t n, mbstate_t *__restrict ps, locale_t loc )
     62 {
     63     __libcpp_locale_guard __current(loc);
     64     return mbrtowc( pwc, s, n, ps );
     65 }
     66 size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
     67                      size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
     68 {
     69     __libcpp_locale_guard __current(loc);
     70     return mbsnrtowcs( dst, src, nms, len, ps );
     71 }
     72 size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
     73                      size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
     74 {
     75     __libcpp_locale_guard __current(loc);
     76     return wcsnrtombs( dst, src, nwc, len, ps );
     77 }
     78 wint_t btowc_l( int c, locale_t loc )
     79 {
     80     __libcpp_locale_guard __current(loc);
     81     return btowc( c );
     82 }
     83 int wctob_l( wint_t c, locale_t loc )
     84 {
     85     __libcpp_locale_guard __current(loc);
     86     return wctob( c );
     87 }
     88 
     89 int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
     90 {
     91     __libcpp_locale_guard __current(loc);
     92     va_list ap;
     93     va_start( ap, format );
     94     int result = vsnprintf( ret, n, format, ap );
     95     va_end(ap);
     96     return result;
     97 }
     98 
     99 int asprintf_l( char **ret, locale_t loc, const char *format, ... )
    100 {
    101     va_list ap;
    102     va_start( ap, format );
    103     int result = vasprintf_l( ret, loc, format, ap );
    104     va_end(ap);
    105     return result;
    106 }
    107 int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap )
    108 {
    109     __libcpp_locale_guard __current(loc);
    110     return __libcpp_vasprintf( ret, format, ap );
    111 }
    112 
    113 #if !defined(_LIBCPP_MSVCRT)
    114 float strtof_l(const char* nptr, char** endptr, locale_t loc) {
    115   __libcpp_locale_guard __current(loc);
    116   return strtof(nptr, endptr);
    117 }
    118 
    119 long double strtold_l(const char* nptr, char** endptr, locale_t loc) {
    120   __libcpp_locale_guard __current(loc);
    121   return strtold(nptr, endptr);
    122 }
    123 #endif
    124