1*04e0dc4aSTimo Kreuzer // 2*04e0dc4aSTimo Kreuzer // wchar.h 3*04e0dc4aSTimo Kreuzer // 4*04e0dc4aSTimo Kreuzer // Copyright (c) Microsoft Corporation. All rights reserved. 5*04e0dc4aSTimo Kreuzer // 6*04e0dc4aSTimo Kreuzer // All of the types, macros, and function declarations for all wide-character 7*04e0dc4aSTimo Kreuzer // related functionality. Most of the functionality is in the #included 8*04e0dc4aSTimo Kreuzer // <corecrt_wxxxx.h> headers, which are also #included by other public headers. 9*04e0dc4aSTimo Kreuzer // 10*04e0dc4aSTimo Kreuzer #pragma once 11*04e0dc4aSTimo Kreuzer #ifndef _INC_WCHAR // include guard for 3rd party interop 12*04e0dc4aSTimo Kreuzer #define _INC_WCHAR 13*04e0dc4aSTimo Kreuzer 14*04e0dc4aSTimo Kreuzer #include <corecrt.h> 15*04e0dc4aSTimo Kreuzer #include <corecrt_memcpy_s.h> 16*04e0dc4aSTimo Kreuzer #include <corecrt_wconio.h> 17*04e0dc4aSTimo Kreuzer #include <corecrt_wctype.h> 18*04e0dc4aSTimo Kreuzer #include <corecrt_wdirect.h> 19*04e0dc4aSTimo Kreuzer #include <corecrt_wio.h> 20*04e0dc4aSTimo Kreuzer #include <corecrt_wprocess.h> 21*04e0dc4aSTimo Kreuzer #include <corecrt_wstdio.h> 22*04e0dc4aSTimo Kreuzer #include <corecrt_wstdlib.h> 23*04e0dc4aSTimo Kreuzer #include <corecrt_wstring.h> 24*04e0dc4aSTimo Kreuzer #include <corecrt_wtime.h> 25*04e0dc4aSTimo Kreuzer #include <sys/stat.h> 26*04e0dc4aSTimo Kreuzer #include <sys/types.h> 27*04e0dc4aSTimo Kreuzer #include <vcruntime_string.h> 28*04e0dc4aSTimo Kreuzer 29*04e0dc4aSTimo Kreuzer #pragma warning(push) 30*04e0dc4aSTimo Kreuzer #pragma warning(disable: _UCRT_DISABLED_WARNINGS) 31*04e0dc4aSTimo Kreuzer _UCRT_DISABLE_CLANG_WARNINGS 32*04e0dc4aSTimo Kreuzer 33*04e0dc4aSTimo Kreuzer _CRT_BEGIN_C_HEADER 34*04e0dc4aSTimo Kreuzer 35*04e0dc4aSTimo Kreuzer 36*04e0dc4aSTimo Kreuzer 37*04e0dc4aSTimo Kreuzer #define WCHAR_MIN 0x0000 38*04e0dc4aSTimo Kreuzer #define WCHAR_MAX 0xffff 39*04e0dc4aSTimo Kreuzer 40*04e0dc4aSTimo Kreuzer 41*04e0dc4aSTimo Kreuzer 42*04e0dc4aSTimo Kreuzer typedef wchar_t _Wint_t; 43*04e0dc4aSTimo Kreuzer 44*04e0dc4aSTimo Kreuzer 45*04e0dc4aSTimo Kreuzer 46*04e0dc4aSTimo Kreuzer #if _CRT_FUNCTIONS_REQUIRED 47*04e0dc4aSTimo Kreuzer 48*04e0dc4aSTimo Kreuzer _Check_return_opt_ _Success_(return != 0) _Ret_z_ 49*04e0dc4aSTimo Kreuzer _ACRTIMP wchar_t* __cdecl _wsetlocale( 50*04e0dc4aSTimo Kreuzer _In_ int _Category, 51*04e0dc4aSTimo Kreuzer _In_opt_z_ wchar_t const* _Locale 52*04e0dc4aSTimo Kreuzer ); 53*04e0dc4aSTimo Kreuzer 54*04e0dc4aSTimo Kreuzer _Check_return_opt_ 55*04e0dc4aSTimo Kreuzer _ACRTIMP _locale_t __cdecl _wcreate_locale( 56*04e0dc4aSTimo Kreuzer _In_ int _Category, 57*04e0dc4aSTimo Kreuzer _In_z_ wchar_t const* _Locale 58*04e0dc4aSTimo Kreuzer ); 59*04e0dc4aSTimo Kreuzer 60*04e0dc4aSTimo Kreuzer 61*04e0dc4aSTimo Kreuzer 62*04e0dc4aSTimo Kreuzer _ACRTIMP wint_t __cdecl btowc( 63*04e0dc4aSTimo Kreuzer _In_ int _Ch 64*04e0dc4aSTimo Kreuzer ); 65*04e0dc4aSTimo Kreuzer 66*04e0dc4aSTimo Kreuzer _ACRTIMP size_t __cdecl mbrlen( 67*04e0dc4aSTimo Kreuzer _In_reads_bytes_opt_(_SizeInBytes) _Pre_opt_z_ char const* _Ch, 68*04e0dc4aSTimo Kreuzer _In_ size_t _SizeInBytes, 69*04e0dc4aSTimo Kreuzer _Inout_ mbstate_t* _State 70*04e0dc4aSTimo Kreuzer ); 71*04e0dc4aSTimo Kreuzer 72*04e0dc4aSTimo Kreuzer _ACRTIMP size_t __cdecl mbrtowc( 73*04e0dc4aSTimo Kreuzer _Pre_maybenull_ _Post_z_ wchar_t* _DstCh, 74*04e0dc4aSTimo Kreuzer _In_reads_bytes_opt_(_SizeInBytes) _Pre_opt_z_ char const* _SrcCh, 75*04e0dc4aSTimo Kreuzer _In_ size_t _SizeInBytes, 76*04e0dc4aSTimo Kreuzer _Inout_ mbstate_t* _State 77*04e0dc4aSTimo Kreuzer ); 78*04e0dc4aSTimo Kreuzer 79*04e0dc4aSTimo Kreuzer _Success_(return == 0) 80*04e0dc4aSTimo Kreuzer _ACRTIMP errno_t __cdecl mbsrtowcs_s( 81*04e0dc4aSTimo Kreuzer _Out_opt_ size_t* _Retval, 82*04e0dc4aSTimo Kreuzer _Out_writes_opt_z_(_Size) wchar_t* _Dst, 83*04e0dc4aSTimo Kreuzer _In_ size_t _Size, 84*04e0dc4aSTimo Kreuzer _Deref_pre_opt_z_ char const** _PSrc, 85*04e0dc4aSTimo Kreuzer _In_ size_t _N, 86*04e0dc4aSTimo Kreuzer _Inout_ mbstate_t* _State 87*04e0dc4aSTimo Kreuzer ); 88*04e0dc4aSTimo Kreuzer 89*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_SECURE_FUNC_1_3( 90*04e0dc4aSTimo Kreuzer _Success_(return == 0) 91*04e0dc4aSTimo Kreuzer errno_t, mbsrtowcs_s, 92*04e0dc4aSTimo Kreuzer _Out_opt_ size_t*, _Retval, 93*04e0dc4aSTimo Kreuzer _Post_z_ wchar_t, _Dest, 94*04e0dc4aSTimo Kreuzer _Inout_ _Deref_prepost_opt_valid_ char const**, _PSource, 95*04e0dc4aSTimo Kreuzer _In_ size_t, _Count, 96*04e0dc4aSTimo Kreuzer _Inout_ mbstate_t*, _State 97*04e0dc4aSTimo Kreuzer ) 98*04e0dc4aSTimo Kreuzer 99*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_3_SIZE( 100*04e0dc4aSTimo Kreuzer _Success_(return == 0) _ACRTIMP, mbsrtowcs, 101*04e0dc4aSTimo Kreuzer _Out_writes_opt_z_(_Count), wchar_t, _Dest, 102*04e0dc4aSTimo Kreuzer _Deref_pre_opt_z_ char const**, _PSrc, 103*04e0dc4aSTimo Kreuzer _In_ size_t, _Count, 104*04e0dc4aSTimo Kreuzer _Inout_ mbstate_t*, _State 105*04e0dc4aSTimo Kreuzer ) 106*04e0dc4aSTimo Kreuzer 107*04e0dc4aSTimo Kreuzer _Success_(return == 0) 108*04e0dc4aSTimo Kreuzer _ACRTIMP errno_t __cdecl wcrtomb_s( 109*04e0dc4aSTimo Kreuzer _Out_opt_ size_t* _Retval, 110*04e0dc4aSTimo Kreuzer _Out_writes_opt_z_(_SizeInBytes) char* _Dst, 111*04e0dc4aSTimo Kreuzer _In_ size_t _SizeInBytes, 112*04e0dc4aSTimo Kreuzer _In_ wchar_t _Ch, 113*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t* _State 114*04e0dc4aSTimo Kreuzer ); 115*04e0dc4aSTimo Kreuzer 116*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_SECURE_FUNC_1_2( 117*04e0dc4aSTimo Kreuzer _Success_(return == 0) 118*04e0dc4aSTimo Kreuzer errno_t, wcrtomb_s, 119*04e0dc4aSTimo Kreuzer _Out_opt_ size_t*, _Retval, 120*04e0dc4aSTimo Kreuzer _Out_writes_opt_z_(_Size) char, _Dest, 121*04e0dc4aSTimo Kreuzer _In_ wchar_t, _Source, 122*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t*, _State 123*04e0dc4aSTimo Kreuzer ) 124*04e0dc4aSTimo Kreuzer 125*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_2_SIZE( 126*04e0dc4aSTimo Kreuzer _ACRTIMP, wcrtomb, 127*04e0dc4aSTimo Kreuzer _Pre_maybenull_ _Post_z_, char, _Dest, 128*04e0dc4aSTimo Kreuzer _In_ wchar_t, _Source, 129*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t*, _State 130*04e0dc4aSTimo Kreuzer ) 131*04e0dc4aSTimo Kreuzer 132*04e0dc4aSTimo Kreuzer _Success_(return == 0) 133*04e0dc4aSTimo Kreuzer _ACRTIMP errno_t __cdecl wcsrtombs_s( 134*04e0dc4aSTimo Kreuzer _Out_opt_ size_t* _Retval, 135*04e0dc4aSTimo Kreuzer _Out_writes_bytes_to_opt_(_SizeInBytes, *_Retval) char* _Dst, 136*04e0dc4aSTimo Kreuzer _In_ size_t _SizeInBytes, 137*04e0dc4aSTimo Kreuzer _Inout_ _Deref_prepost_z_ wchar_t const** _Src, 138*04e0dc4aSTimo Kreuzer _In_ size_t _Size, 139*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t* _State 140*04e0dc4aSTimo Kreuzer ); 141*04e0dc4aSTimo Kreuzer 142*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_SECURE_FUNC_1_3( 143*04e0dc4aSTimo Kreuzer _Success_(return == 0) 144*04e0dc4aSTimo Kreuzer errno_t, wcsrtombs_s, 145*04e0dc4aSTimo Kreuzer _Out_opt_ size_t*, _Retval, 146*04e0dc4aSTimo Kreuzer _Out_writes_opt_z_(_Size) char, _Dest, 147*04e0dc4aSTimo Kreuzer _Inout_ _Deref_prepost_z_ wchar_t const**, _PSrc, 148*04e0dc4aSTimo Kreuzer _In_ size_t, _Count, 149*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t*, _State 150*04e0dc4aSTimo Kreuzer ) 151*04e0dc4aSTimo Kreuzer 152*04e0dc4aSTimo Kreuzer __DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_3_SIZE( 153*04e0dc4aSTimo Kreuzer _ACRTIMP, wcsrtombs, 154*04e0dc4aSTimo Kreuzer _Pre_maybenull_ _Post_z_, char, _Dest, 155*04e0dc4aSTimo Kreuzer _Inout_ _Deref_prepost_z_ wchar_t const**, _PSource, 156*04e0dc4aSTimo Kreuzer _In_ size_t, _Count, 157*04e0dc4aSTimo Kreuzer _Inout_opt_ mbstate_t*, _State 158*04e0dc4aSTimo Kreuzer ) 159*04e0dc4aSTimo Kreuzer 160*04e0dc4aSTimo Kreuzer _ACRTIMP int __cdecl wctob( 161*04e0dc4aSTimo Kreuzer _In_ wint_t _WCh 162*04e0dc4aSTimo Kreuzer ); 163*04e0dc4aSTimo Kreuzer 164*04e0dc4aSTimo Kreuzer #if __STDC_WANT_SECURE_LIB__ 165*04e0dc4aSTimo Kreuzer 166*04e0dc4aSTimo Kreuzer _Success_(return == 0) 167*04e0dc4aSTimo Kreuzer errno_t __CRTDECL wmemcpy_s( 168*04e0dc4aSTimo Kreuzer _Out_writes_to_opt_(_N1, _N) wchar_t* _S1, 169*04e0dc4aSTimo Kreuzer _In_ rsize_t _N1, 170*04e0dc4aSTimo Kreuzer _In_reads_opt_(_N) wchar_t const* _S2, 171*04e0dc4aSTimo Kreuzer _In_ rsize_t _N 172*04e0dc4aSTimo Kreuzer ); 173*04e0dc4aSTimo Kreuzer 174*04e0dc4aSTimo Kreuzer _Success_(return == 0) 175*04e0dc4aSTimo Kreuzer errno_t __CRTDECL wmemmove_s( 176*04e0dc4aSTimo Kreuzer _Out_writes_to_opt_(_N1, _N) wchar_t* _S1, 177*04e0dc4aSTimo Kreuzer _In_ rsize_t _N1, 178*04e0dc4aSTimo Kreuzer _In_reads_opt_(_N) wchar_t const* _S2, 179*04e0dc4aSTimo Kreuzer _In_ rsize_t _N 180*04e0dc4aSTimo Kreuzer ); 181*04e0dc4aSTimo Kreuzer 182*04e0dc4aSTimo Kreuzer #endif // __STDC_WANT_SECURE_LIB__ 183*04e0dc4aSTimo Kreuzer fwide(_In_opt_ FILE * _F,_In_ int _M)184*04e0dc4aSTimo Kreuzer __inline int __CRTDECL fwide( 185*04e0dc4aSTimo Kreuzer _In_opt_ FILE* _F, 186*04e0dc4aSTimo Kreuzer _In_ int _M 187*04e0dc4aSTimo Kreuzer ) 188*04e0dc4aSTimo Kreuzer { 189*04e0dc4aSTimo Kreuzer _CRT_UNUSED(_F); 190*04e0dc4aSTimo Kreuzer return (_M); 191*04e0dc4aSTimo Kreuzer } 192*04e0dc4aSTimo Kreuzer mbsinit(_In_opt_ mbstate_t const * _P)193*04e0dc4aSTimo Kreuzer __inline int __CRTDECL mbsinit( 194*04e0dc4aSTimo Kreuzer _In_opt_ mbstate_t const* _P 195*04e0dc4aSTimo Kreuzer ) 196*04e0dc4aSTimo Kreuzer { 197*04e0dc4aSTimo Kreuzer return _P == NULL || _P->_Wchar == 0; 198*04e0dc4aSTimo Kreuzer } 199*04e0dc4aSTimo Kreuzer wmemchr(_In_reads_ (_N)wchar_t const * _S,_In_ wchar_t _C,_In_ size_t _N)200*04e0dc4aSTimo Kreuzer __inline wchar_t _CONST_RETURN* __CRTDECL wmemchr( 201*04e0dc4aSTimo Kreuzer _In_reads_(_N) wchar_t const* _S, 202*04e0dc4aSTimo Kreuzer _In_ wchar_t _C, 203*04e0dc4aSTimo Kreuzer _In_ size_t _N 204*04e0dc4aSTimo Kreuzer ) 205*04e0dc4aSTimo Kreuzer { 206*04e0dc4aSTimo Kreuzer for (; 0 < _N; ++_S, --_N) 207*04e0dc4aSTimo Kreuzer if (*_S == _C) 208*04e0dc4aSTimo Kreuzer return (wchar_t _CONST_RETURN*)_S; 209*04e0dc4aSTimo Kreuzer 210*04e0dc4aSTimo Kreuzer return 0; 211*04e0dc4aSTimo Kreuzer } 212*04e0dc4aSTimo Kreuzer wmemcmp(_In_reads_ (_N)wchar_t const * _S1,_In_reads_ (_N)wchar_t const * _S2,_In_ size_t _N)213*04e0dc4aSTimo Kreuzer __inline int __CRTDECL wmemcmp( 214*04e0dc4aSTimo Kreuzer _In_reads_(_N) wchar_t const* _S1, 215*04e0dc4aSTimo Kreuzer _In_reads_(_N) wchar_t const* _S2, 216*04e0dc4aSTimo Kreuzer _In_ size_t _N 217*04e0dc4aSTimo Kreuzer ) 218*04e0dc4aSTimo Kreuzer { 219*04e0dc4aSTimo Kreuzer for (; 0 < _N; ++_S1, ++_S2, --_N) 220*04e0dc4aSTimo Kreuzer if (*_S1 != *_S2) 221*04e0dc4aSTimo Kreuzer return *_S1 < *_S2 ? -1 : 1; 222*04e0dc4aSTimo Kreuzer 223*04e0dc4aSTimo Kreuzer return 0; 224*04e0dc4aSTimo Kreuzer } 225*04e0dc4aSTimo Kreuzer 226*04e0dc4aSTimo Kreuzer _Post_equal_to_(_S1) 227*04e0dc4aSTimo Kreuzer _At_buffer_(_S1, _Iter_, _N, _Post_satisfies_(_S1[_Iter_] == _S2[_Iter_])) _CRT_INSECURE_DEPRECATE_MEMORY(wmemcpy_s)228*04e0dc4aSTimo Kreuzer __inline _CRT_INSECURE_DEPRECATE_MEMORY(wmemcpy_s) 229*04e0dc4aSTimo Kreuzer wchar_t* __CRTDECL wmemcpy( 230*04e0dc4aSTimo Kreuzer _Out_writes_all_(_N) wchar_t* _S1, 231*04e0dc4aSTimo Kreuzer _In_reads_(_N) wchar_t const* _S2, 232*04e0dc4aSTimo Kreuzer _In_ size_t _N 233*04e0dc4aSTimo Kreuzer ) 234*04e0dc4aSTimo Kreuzer { 235*04e0dc4aSTimo Kreuzer #pragma warning(suppress: 6386) // Buffer overrun 236*04e0dc4aSTimo Kreuzer return (wchar_t*)memcpy(_S1, _S2, _N*sizeof(wchar_t)); 237*04e0dc4aSTimo Kreuzer } 238*04e0dc4aSTimo Kreuzer _CRT_INSECURE_DEPRECATE_MEMORY(wmemmove_s)239*04e0dc4aSTimo Kreuzer __inline _CRT_INSECURE_DEPRECATE_MEMORY(wmemmove_s) 240*04e0dc4aSTimo Kreuzer wchar_t* __CRTDECL wmemmove( 241*04e0dc4aSTimo Kreuzer _Out_writes_all_opt_(_N) wchar_t* _S1, 242*04e0dc4aSTimo Kreuzer _In_reads_opt_(_N) wchar_t const* _S2, 243*04e0dc4aSTimo Kreuzer _In_ size_t _N 244*04e0dc4aSTimo Kreuzer ) 245*04e0dc4aSTimo Kreuzer { 246*04e0dc4aSTimo Kreuzer #pragma warning(suppress: 6386) // Buffer overrun 247*04e0dc4aSTimo Kreuzer return (wchar_t*)memmove(_S1, _S2, _N*sizeof(wchar_t)); 248*04e0dc4aSTimo Kreuzer } 249*04e0dc4aSTimo Kreuzer 250*04e0dc4aSTimo Kreuzer _Post_equal_to_(_S) 251*04e0dc4aSTimo Kreuzer _At_buffer_(_S, _Iter_, _N, _Post_satisfies_(_S[_Iter_] == _C)) wmemset(_Out_writes_all_ (_N)wchar_t * _S,_In_ wchar_t _C,_In_ size_t _N)252*04e0dc4aSTimo Kreuzer __inline wchar_t* __CRTDECL wmemset( 253*04e0dc4aSTimo Kreuzer _Out_writes_all_(_N) wchar_t* _S, 254*04e0dc4aSTimo Kreuzer _In_ wchar_t _C, 255*04e0dc4aSTimo Kreuzer _In_ size_t _N 256*04e0dc4aSTimo Kreuzer ) 257*04e0dc4aSTimo Kreuzer { 258*04e0dc4aSTimo Kreuzer wchar_t *_Su = _S; 259*04e0dc4aSTimo Kreuzer for (; 0 < _N; ++_Su, --_N) 260*04e0dc4aSTimo Kreuzer { 261*04e0dc4aSTimo Kreuzer *_Su = _C; 262*04e0dc4aSTimo Kreuzer } 263*04e0dc4aSTimo Kreuzer return _S; 264*04e0dc4aSTimo Kreuzer } 265*04e0dc4aSTimo Kreuzer 266*04e0dc4aSTimo Kreuzer #ifdef __cplusplus 267*04e0dc4aSTimo Kreuzer wmemchr(_In_reads_ (_N)wchar_t * _S,_In_ wchar_t _C,_In_ size_t _N)268*04e0dc4aSTimo Kreuzer extern "C++" inline wchar_t* __CRTDECL wmemchr( 269*04e0dc4aSTimo Kreuzer _In_reads_(_N) wchar_t* _S, 270*04e0dc4aSTimo Kreuzer _In_ wchar_t _C, 271*04e0dc4aSTimo Kreuzer _In_ size_t _N 272*04e0dc4aSTimo Kreuzer ) 273*04e0dc4aSTimo Kreuzer { 274*04e0dc4aSTimo Kreuzer wchar_t const* const _SC = _S; 275*04e0dc4aSTimo Kreuzer return const_cast<wchar_t*>(wmemchr(_SC, _C, _N)); 276*04e0dc4aSTimo Kreuzer } 277*04e0dc4aSTimo Kreuzer 278*04e0dc4aSTimo Kreuzer #endif // __cplusplus 279*04e0dc4aSTimo Kreuzer 280*04e0dc4aSTimo Kreuzer #endif // _CRT_FUNCTIONS_REQUIRED 281*04e0dc4aSTimo Kreuzer 282*04e0dc4aSTimo Kreuzer 283*04e0dc4aSTimo Kreuzer _CRT_END_C_HEADER 284*04e0dc4aSTimo Kreuzer _UCRT_RESTORE_CLANG_WARNINGS 285*04e0dc4aSTimo Kreuzer #pragma warning(pop) // _UCRT_DISABLED_WARNINGS 286*04e0dc4aSTimo Kreuzer #endif // _INC_WCHAR 287