diff options
author | Howard Hinnant <hhinnant@apple.com> | 2011-09-23 16:11:27 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2011-09-23 16:11:27 +0000 |
commit | dbe8111948d372a6f7445e86a0ac985717fbe1bc (patch) | |
tree | c1b32170cbebef28cb095d90a69cbea28a050397 /libcxx/src | |
parent | a54fd541c23916eb65b252da1690516cb09f6731 (diff) | |
download | bcm5719-llvm-dbe8111948d372a6f7445e86a0ac985717fbe1bc.tar.gz bcm5719-llvm-dbe8111948d372a6f7445e86a0ac985717fbe1bc.zip |
Work on Windows port by Ruben Van Boxem
llvm-svn: 140384
Diffstat (limited to 'libcxx/src')
-rw-r--r-- | libcxx/src/locale.cpp | 30 | ||||
-rw-r--r-- | libcxx/src/string.cpp | 3 | ||||
-rw-r--r-- | libcxx/src/support/win32/support.cpp | 43 | ||||
-rw-r--r-- | libcxx/src/thread.cpp | 2 |
4 files changed, 76 insertions, 2 deletions
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp index 8f1e4e1322b..388660d2d85 100644 --- a/libcxx/src/locale.cpp +++ b/libcxx/src/locale.cpp @@ -19,7 +19,11 @@ #include "cstring" #include "cwctype" #include "__sso_allocator" +#if _WIN32 +#include <locale.h> +#else // _WIN32 #include <langinfo.h> +#endif // _!WIN32 #include <stdlib.h> #ifdef _LIBCPP_STABLE_APPLE_ABI @@ -5568,16 +5572,29 @@ moneypunct_byname<char, true>::init(const char* nm) __frac_digits_ = lc->int_frac_digits; else __frac_digits_ = base::do_frac_digits(); +#if _WIN32 + if (lc->p_sign_posn == 0) +#else // _WIN32 if (lc->int_p_sign_posn == 0) +#endif //_WIN32 __positive_sign_ = "()"; else __positive_sign_ = lc->positive_sign; +#if _WIN32 + if(lc->n_sign_posn == 0) +#else // _WIN32 if (lc->int_n_sign_posn == 0) +#endif // _WIN32 __negative_sign_ = "()"; else __negative_sign_ = lc->negative_sign; +#if _WIN32 + __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn); + __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn); +#else __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); +#endif // _WIN32 } template<> @@ -5698,7 +5715,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) __frac_digits_ = lc->int_frac_digits; else __frac_digits_ = base::do_frac_digits(); +#if _WIN32 + if (lc->p_sign_posn == 0) +#else // _WIN32 if (lc->int_p_sign_posn == 0) +#endif // _WIN32 __positive_sign_ = L"()"; else { @@ -5714,7 +5735,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) wbe = wbuf + j; __positive_sign_.assign(wbuf, wbe); } +#if _WIN32 + if (lc->n_sign_posn == 0) +#else // _WIN32 if (lc->int_n_sign_posn == 0) +#endif // _WIN32 __negative_sign_ = L"()"; else { @@ -5730,8 +5755,13 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) wbe = wbuf + j; __negative_sign_.assign(wbuf, wbe); } +#if _WIN32 + __init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn); + __init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn); +#else // _WIN32 __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); +#endif // _WIN32 } void __do_nothing(void*) {} diff --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp index 7e651a1a8e0..1f58e3657a8 100644 --- a/libcxx/src/string.cpp +++ b/libcxx/src/string.cpp @@ -11,6 +11,9 @@ #include "cstdlib" #include "cwchar" #include "cerrno" +#if _WIN32 +#include "support/win32/support.h" +#endif // _WIN32 _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/libcxx/src/support/win32/support.cpp b/libcxx/src/support/win32/support.cpp index 7033809bd2a..db80063c690 100644 --- a/libcxx/src/support/win32/support.cpp +++ b/libcxx/src/support/win32/support.cpp @@ -8,11 +8,17 @@ // //===----------------------------------------------------------------------===// +#include <stddef.h> // size_t +#include <stdlib.h> // malloc +#include <stdio.h> // vsprintf, vsnprintf +#include <string.h> // strcpy, wcsncpy +#include <wchar.h> // mbstate_t + int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap ) { - *sptr = NULL + *sptr = NULL; int count = vsnprintf( *sptr, 0, fmt, ap ); - if( (count >= 0) && ((*sptr = malloc(count+1)) != NULL) ) + if( (count >= 0) && ((*sptr = (char*)malloc(count+1)) != NULL) ) { vsprintf( *sptr, fmt, ap ); sptr[count] = '\0'; @@ -20,3 +26,36 @@ int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap ) return count; } + +// FIXME: use wcrtomb and avoid copy +// use mbsrtowcs which is available, first copy first nwc elements of src +size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src, + size_t nmc, size_t len, mbstate_t *__restrict__ ps ) +{ + char* local_src = new char[nmc+1]; + char* nmcsrc = local_src; + strncpy( nmcsrc, *src, nmc ); + nmcsrc[nmc] = '\0'; + const size_t result = mbsrtowcs( dst, const_cast<const char **>(&nmcsrc), len, ps ); + // propagate error + if( nmcsrc == NULL ) + *src = NULL; + delete[] local_src; + return result; +} +// FIXME: use wcrtomb and avoid copy +// use wcsrtombs which is available, first copy first nwc elements of src +size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src, + size_t nwc, size_t len, mbstate_t *__restrict__ ps ) +{ + wchar_t* local_src = new wchar_t[nwc]; + wchar_t* nwcsrc = local_src; + wcsncpy(nwcsrc, *src, nwc); + nwcsrc[nwc] = '\0'; + const size_t result = wcsrtombs( dst, const_cast<const wchar_t **>(&nwcsrc), len, ps ); + // propogate error + if( nwcsrc == NULL ) + *src = NULL; + delete[] nwcsrc; + return result; +} diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp index 4ccff3277f5..b07f8f85107 100644 --- a/libcxx/src/thread.cpp +++ b/libcxx/src/thread.cpp @@ -12,7 +12,9 @@ #include "vector" #include "future" #include <sys/types.h> +#if !_WIN32 #include <sys/sysctl.h> +#endif // _WIN32 _LIBCPP_BEGIN_NAMESPACE_STD |