2 * msvcrt.dll wide-char functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
36 static BOOL n_format_enabled
= TRUE
;
43 /* _get_printf_count_output - not exported in native msvcrt */
44 int CDECL
MSVCRT__get_printf_count_output( void )
46 return n_format_enabled
? 1 : 0;
49 /* _set_printf_count_output - not exported in native msvcrt */
50 int CDECL
MSVCRT__set_printf_count_output( int enable
)
52 BOOL old
= n_format_enabled
;
53 n_format_enabled
= enable
!= 0;
57 /*********************************************************************
60 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsdup( const MSVCRT_wchar_t
* str
)
62 MSVCRT_wchar_t
* ret
= NULL
;
65 int size
= (strlenW(str
) + 1) * sizeof(MSVCRT_wchar_t
);
66 ret
= MSVCRT_malloc( size
);
67 if (ret
) memcpy( ret
, str
, size
);
72 INT CDECL
MSVCRT__wcsicmp_l(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, MSVCRT__locale_t locale
)
74 if(!MSVCRT_CHECK_PMT(str1
!= NULL
) || !MSVCRT_CHECK_PMT(str2
!= NULL
))
75 return MSVCRT__NLSCMPERROR
;
77 return strcmpiW(str1
, str2
);
80 /*********************************************************************
83 INT CDECL
MSVCRT__wcsicmp( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
85 return strcmpiW( str1
, str2
);
88 /*********************************************************************
89 * _wcsnicmp (MSVCRT.@)
91 INT CDECL
MSVCRT__wcsnicmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
)
93 return strncmpiW(str1
, str2
, n
);
96 /*********************************************************************
97 * _wcsicoll_l (MSVCRT.@)
99 int CDECL
MSVCRT__wcsicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
101 MSVCRT_pthreadlocinfo locinfo
;
104 locinfo
= get_locinfo();
106 locinfo
= locale
->locinfo
;
108 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
109 str1
, -1, str2
, -1)-CSTR_EQUAL
;
112 /*********************************************************************
113 * _wcsicoll (MSVCRT.@)
115 INT CDECL
MSVCRT__wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
117 return MSVCRT__wcsicoll_l(str1
, str2
, NULL
);
120 /*********************************************************************
121 * _wcsnicoll_l (MSVCRT.@)
123 int CDECL
MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
124 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
126 MSVCRT_pthreadlocinfo locinfo
;
129 locinfo
= get_locinfo();
131 locinfo
= locale
->locinfo
;
133 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
134 str1
, count
, str2
, count
)-CSTR_EQUAL
;
137 /*********************************************************************
138 * _wcsnicoll (MSVCRT.@)
140 INT CDECL
MSVCRT__wcsnicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
142 return MSVCRT__wcsnicoll_l(str1
, str2
, count
, NULL
);
145 /*********************************************************************
146 * _wcsnset (MSVCRT.@)
148 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
150 MSVCRT_wchar_t
* ret
= str
;
151 while ((n
-- > 0) && *str
) *str
++ = c
;
155 /*********************************************************************
158 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsrev( MSVCRT_wchar_t
* str
)
160 MSVCRT_wchar_t
* ret
= str
;
161 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
164 MSVCRT_wchar_t t
= *end
;
171 /*********************************************************************
174 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
176 MSVCRT_wchar_t
* ret
= str
;
177 while (*str
) *str
++ = c
;
181 /******************************************************************
182 * _wcsupr_s_l (MSVCRT.@)
184 int CDECL
MSVCRT__wcsupr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
,
185 MSVCRT__locale_t locale
)
187 MSVCRT_wchar_t
* ptr
= str
;
191 if (str
) *str
= '\0';
192 *MSVCRT__errno() = MSVCRT_EINVAL
;
193 return MSVCRT_EINVAL
;
199 /* FIXME: add locale support */
200 *ptr
= toupperW(*ptr
);
204 /* MSDN claims that the function should return and set errno to
205 * ERANGE, which doesn't seem to be true based on the tests. */
207 *MSVCRT__errno() = MSVCRT_EINVAL
;
208 return MSVCRT_EINVAL
;
211 /******************************************************************
212 * _wcsupr_s (MSVCRT.@)
215 INT CDECL
MSVCRT__wcsupr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
217 return MSVCRT__wcsupr_s_l( str
, n
, NULL
);
220 /******************************************************************
221 * _wcslwr_s (MSVCRT.@)
223 int CDECL
MSVCRT__wcslwr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
225 MSVCRT_wchar_t
* ptr
= str
;
229 if (str
) *str
= '\0';
230 *MSVCRT__errno() = MSVCRT_EINVAL
;
231 return MSVCRT_EINVAL
;
237 *ptr
= tolowerW(*ptr
);
241 /* MSDN claims that the function should return and set errno to
242 * ERANGE, which doesn't seem to be true based on the tests. */
244 *MSVCRT__errno() = MSVCRT_EINVAL
;
245 return MSVCRT_EINVAL
;
248 /*********************************************************************
249 * _wcsncoll_l (MSVCRT.@)
251 int CDECL
MSVCRT__wcsncoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
252 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
254 MSVCRT_pthreadlocinfo locinfo
;
257 locinfo
= get_locinfo();
259 locinfo
= locale
->locinfo
;
261 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, count
, str2
, count
)-CSTR_EQUAL
;
264 /*********************************************************************
265 * _wcsncoll (MSVCRT.@)
267 int CDECL
MSVCRT__wcsncoll(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
269 return MSVCRT__wcsncoll_l(str1
, str2
, count
, NULL
);
272 /*********************************************************************
273 * _wcstod_l (MSVCRT.@)
275 double CDECL
MSVCRT__wcstod_l(const MSVCRT_wchar_t
* str
, MSVCRT_wchar_t
** end
,
276 MSVCRT__locale_t locale
)
278 MSVCRT_pthreadlocinfo locinfo
;
279 unsigned __int64 d
=0, hlp
;
282 const MSVCRT_wchar_t
*p
;
284 long double lret
=1, expcnt
= 10;
285 BOOL found_digit
= FALSE
, negexp
;
287 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
290 locinfo
= get_locinfo();
292 locinfo
= locale
->locinfo
;
304 while(isdigitW(*p
)) {
306 hlp
= d
*10+*(p
++)-'0';
307 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
313 while(isdigitW(*p
)) {
317 if(*p
== *locinfo
->lconv
->decimal_point
)
320 while(isdigitW(*p
)) {
322 hlp
= d
*10+*(p
++)-'0';
323 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
334 *end
= (MSVCRT_wchar_t
*)str
;
338 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
349 while(isdigitW(*p
)) {
350 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
356 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
357 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
360 if(*p
=='-' || *p
=='+')
366 fpcontrol
= _control87(0, 0);
367 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
368 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
377 expcnt
= expcnt
*expcnt
;
379 ret
= (long double)sign
* (negexp
? d
/lret
: d
*lret
);
381 _control87(fpcontrol
, 0xffffffff);
383 if((d
&& ret
==0.0) || isinf(ret
))
384 *MSVCRT__errno() = MSVCRT_ERANGE
;
387 *end
= (MSVCRT_wchar_t
*)p
;
392 /*********************************************************************
393 * wcsrtombs_l (INTERNAL)
395 static MSVCRT_size_t
MSVCRT_wcsrtombs_l(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
396 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
398 MSVCRT_pthreadlocinfo locinfo
;
399 MSVCRT_size_t tmp
= 0;
403 locinfo
= get_locinfo();
405 locinfo
= locale
->locinfo
;
408 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
409 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
410 if(!tmp
|| used_default
) {
411 *MSVCRT__errno() = MSVCRT_EILSEQ
;
419 MSVCRT_size_t i
, size
;
421 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
422 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
423 if(!size
|| used_default
) {
424 *MSVCRT__errno() = MSVCRT_EILSEQ
;
430 for(i
=0; i
<size
; i
++)
431 mbstr
[tmp
++] = buf
[i
];
442 /*********************************************************************
443 * _wcstombs_l (MSVCRT.@)
445 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
446 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
448 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
451 /*********************************************************************
452 * wcstombs (MSVCRT.@)
454 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
457 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
460 /*********************************************************************
461 * wcsrtombs (MSVCRT.@)
463 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
464 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
469 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
472 /*********************************************************************
473 * MSVCRT_wcsrtombs_s_l (INTERNAL)
475 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
476 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
477 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
481 if(!mbstr
&& !size
&& wcstr
) {
482 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
484 return *MSVCRT__errno();
490 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
491 if (size
) mbstr
[0] = '\0';
492 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
493 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
495 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
500 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
504 return *MSVCRT__errno();
505 }else if(conv
< size
)
506 mbstr
[conv
++] = '\0';
507 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
508 mbstr
[conv
-1] = '\0';
510 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
513 return MSVCRT_ERANGE
;
521 /*********************************************************************
522 * _wcstombs_s_l (MSVCRT.@)
524 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
525 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
526 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
528 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
531 /*********************************************************************
532 * wcstombs_s (MSVCRT.@)
534 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
535 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
537 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
540 /*********************************************************************
541 * wcsrtombs_s (MSVCRT.@)
543 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
544 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
549 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
552 /*********************************************************************
555 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
557 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
560 /*********************************************************************
563 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
565 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
568 /*********************************************************************
571 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
573 return MSVCRT__wcstod_l(str
, NULL
, locale
);
576 /*********************************************************************
577 * arg_clbk_valist (INTERNAL)
579 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
584 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
585 else if(type
== VT_INT
)
586 ret
.get_int
= va_arg(*valist
, int);
587 else if(type
== VT_R8
)
588 ret
.get_double
= va_arg(*valist
, double);
589 else if(type
== VT_PTR
)
590 ret
.get_ptr
= va_arg(*valist
, void*);
592 ERR("Incorrect type\n");
599 /*********************************************************************
600 * arg_clbk_positional (INTERNAL)
602 static printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
604 printf_arg
*args
= ctx
;
608 /*********************************************************************
609 * _vsnprintf (MSVCRT.@)
611 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
612 const char *format
, __ms_va_list valist
)
614 static const char nullbyte
= '\0';
615 struct _str_ctx_a ctx
= {len
, str
};
618 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, FALSE
, FALSE
,
619 arg_clbk_valist
, NULL
, &valist
);
620 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
624 /*********************************************************************
625 * _vsnprintf_l (MSVCRT.@)
627 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
628 MSVCRT__locale_t locale
, __ms_va_list valist
)
630 static const char nullbyte
= '\0';
631 struct _str_ctx_a ctx
= {len
, str
};
634 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, FALSE
,
635 arg_clbk_valist
, NULL
, &valist
);
636 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
640 /*********************************************************************
641 * _vsnprintf_s_l (MSVCRT.@)
643 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
644 MSVCRT_size_t count
, const char *format
,
645 MSVCRT__locale_t locale
, __ms_va_list valist
)
647 static const char nullbyte
= '\0';
648 struct _str_ctx_a ctx
;
651 if(sizeOfBuffer
<count
+1 || count
==-1)
658 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, TRUE
,
659 arg_clbk_valist
, NULL
, &valist
);
660 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
662 if(ret
<0 || ret
==len
) {
663 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
664 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
665 memset(str
, 0, sizeOfBuffer
);
675 /*********************************************************************
676 * _vsnprintf_s (MSVCRT.@)
678 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
679 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
681 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
684 /*********************************************************************
685 * vsprintf (MSVCRT.@)
687 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
689 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
692 /*********************************************************************
693 * vsprintf_s (MSVCRT.@)
695 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
697 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
700 /*********************************************************************
701 * _vscprintf (MSVCRT.@)
703 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
705 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
708 /*********************************************************************
709 * _snprintf (MSVCRT.@)
711 int CDECL
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
715 __ms_va_start(valist
, format
);
716 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
721 /*********************************************************************
722 * _snprintf_s (MSVCRT.@)
724 int CDECL
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
725 const char *format
, ...)
729 __ms_va_start(valist
, format
);
730 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
735 /*********************************************************************
736 * _scprintf (MSVCRT.@)
738 int CDECL
MSVCRT__scprintf(const char *format
, ...)
742 __ms_va_start(valist
, format
);
743 retval
= MSVCRT__vscprintf(format
, valist
);
748 /*********************************************************************
749 * _vsnwprintf (MSVCRT.@)
751 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
752 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
754 static const MSVCRT_wchar_t nullbyte
= '\0';
755 struct _str_ctx_w ctx
= {len
, str
};
758 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, FALSE
, FALSE
,
759 arg_clbk_valist
, NULL
, &valist
);
760 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
764 /*********************************************************************
765 * _vsnwprintf_l (MSVCRT.@)
767 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
768 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
771 static const MSVCRT_wchar_t nullbyte
= '\0';
772 struct _str_ctx_w ctx
= {len
, str
};
775 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, FALSE
,
776 arg_clbk_valist
, NULL
, &valist
);
777 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
781 /*********************************************************************
782 * _vswprintf_p_l (MSVCRT.@)
784 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
785 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
787 static const MSVCRT_wchar_t nullbyte
= '\0';
788 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
789 struct _str_ctx_w puts_ctx
= {length
, buffer
};
792 memset(args_ctx
, 0, sizeof(args_ctx
));
794 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
796 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
797 *MSVCRT__errno() = MSVCRT_EINVAL
;
800 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
801 arg_clbk_valist
, NULL
, &args
);
803 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
804 arg_clbk_positional
, args_ctx
, NULL
);
806 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
810 /*********************************************************************
811 * _vsnwprintf_s_l (MSVCRT.@)
813 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
814 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
815 MSVCRT__locale_t locale
, __ms_va_list valist
)
817 static const MSVCRT_wchar_t nullbyte
= '\0';
818 struct _str_ctx_w ctx
;
822 if(count
!=-1 && len
>count
+1)
827 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, TRUE
,
828 arg_clbk_valist
, NULL
, &valist
);
829 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
831 if(ret
<0 || ret
==len
) {
832 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
833 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
834 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
844 /*********************************************************************
845 * _vsnwprintf_s (MSVCRT.@)
847 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
848 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
850 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
851 format
, NULL
, valist
);
854 /*********************************************************************
855 * _snwprintf (MSVCRT.@)
857 int CDECL
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
861 __ms_va_start(valist
, format
);
862 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
867 /*********************************************************************
868 * _snwprintf_l (MSVCRT.@)
870 int CDECL
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
871 MSVCRT__locale_t locale
, ...)
875 __ms_va_start(valist
, locale
);
876 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
881 /*********************************************************************
882 * _snwprintf_s (MSVCRT.@)
884 int CDECL
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
885 const MSVCRT_wchar_t
*format
, ...)
889 __ms_va_start(valist
, format
);
890 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
895 /*********************************************************************
896 * _snwprintf_s_l (MSVCRT.@)
898 int CDECL
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
899 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
903 __ms_va_start(valist
, locale
);
904 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
909 /*********************************************************************
912 int CDECL
MSVCRT_sprintf( char *str
, const char *format
, ... )
917 __ms_va_start( ap
, format
);
918 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
923 /*********************************************************************
924 * sprintf_s (MSVCRT.@)
926 int CDECL
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
931 __ms_va_start( ap
, format
);
932 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
937 /*********************************************************************
938 * _scwprintf (MSVCRT.@)
940 int CDECL
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
945 __ms_va_start( ap
, format
);
946 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
951 /*********************************************************************
952 * swprintf (MSVCRT.@)
954 int CDECL
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
959 __ms_va_start( ap
, format
);
960 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
965 /*********************************************************************
966 * swprintf_s (MSVCRT.@)
968 int CDECL
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
969 const MSVCRT_wchar_t
*format
, ... )
974 __ms_va_start(ap
, format
);
975 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
981 /*********************************************************************
982 * _swprintf_s_l (MSVCRT.@)
984 int CDECL
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
985 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
990 __ms_va_start(ap
, locale
);
991 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
997 /*********************************************************************
998 * _vswprintf (MSVCRT.@)
1000 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1002 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1005 /*********************************************************************
1006 * _vswprintf (MSVCRT.@)
1008 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1009 MSVCRT__locale_t locale
, __ms_va_list args
)
1011 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1014 /*********************************************************************
1015 * _vscwprintf (MSVCRT.@)
1017 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1019 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1022 /*********************************************************************
1023 * _vscwprintf_l (MSVCRT.@)
1025 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1027 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1030 /*********************************************************************
1031 * _vscwprintf_p_l (MSVCRT.@)
1033 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1035 return MSVCRT_vswprintf_p_l( NULL
, INT_MAX
, format
, locale
, args
);
1038 /*********************************************************************
1039 * vswprintf_s (MSVCRT.@)
1041 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1042 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1044 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1047 /*********************************************************************
1048 * _vswprintf_s_l (MSVCRT.@)
1050 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1051 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1053 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1054 format
, locale
, args
);
1057 /*********************************************************************
1058 * _vsprintf_p_l (MSVCRT.@)
1060 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1061 MSVCRT__locale_t locale
, __ms_va_list args
)
1063 static const char nullbyte
= '\0';
1064 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1065 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1068 memset(args_ctx
, 0, sizeof(args_ctx
));
1070 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1072 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1073 *MSVCRT__errno() = MSVCRT_EINVAL
;
1076 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
1077 arg_clbk_valist
, NULL
, &args
);
1079 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
1080 arg_clbk_positional
, args_ctx
, NULL
);
1082 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1086 /*********************************************************************
1087 * _vsprintf_p (MSVCRT.@)
1089 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1090 const char *format
, __ms_va_list args
)
1092 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1095 /*********************************************************************
1096 * _sprintf_p_l (MSVCRT.@)
1098 int CDECL
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1099 const char *format
, MSVCRT__locale_t locale
, ...)
1101 __ms_va_list valist
;
1104 __ms_va_start(valist
, locale
);
1105 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1106 __ms_va_end(valist
);
1111 /*********************************************************************
1112 * _swprintf_p_l (MSVCRT.@)
1114 int CDECL
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1115 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1117 __ms_va_list valist
;
1120 __ms_va_start(valist
, locale
);
1121 r
= MSVCRT_vswprintf_p_l(buffer
, length
, format
, locale
, valist
);
1122 __ms_va_end(valist
);
1127 /*********************************************************************
1128 * _wcscoll_l (MSVCRT.@)
1130 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1132 MSVCRT_pthreadlocinfo locinfo
;
1135 locinfo
= get_locinfo();
1137 locinfo
= locale
->locinfo
;
1139 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1142 /*********************************************************************
1143 * wcscoll (MSVCRT.@)
1145 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1147 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1150 /*********************************************************************
1151 * wcspbrk (MSVCRT.@)
1153 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1155 const MSVCRT_wchar_t
* p
;
1159 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1165 /*********************************************************************
1166 * wcstok_s (MSVCRT.@)
1168 MSVCRT_wchar_t
* CDECL
wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1169 MSVCRT_wchar_t
**next_token
)
1171 MSVCRT_wchar_t
*ret
;
1173 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1174 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1175 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1177 if (!str
) str
= *next_token
;
1179 while (*str
&& strchrW( delim
, *str
)) str
++;
1180 if (!*str
) return NULL
;
1182 while (*str
&& !strchrW( delim
, *str
)) str
++;
1183 if (*str
) *str
++ = 0;
1188 /*********************************************************************
1191 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1193 return wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1196 /*********************************************************************
1197 * _wctomb_s_l (MSVCRT.@)
1199 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1200 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1202 MSVCRT_pthreadlocinfo locinfo
;
1206 if(!mbchar
&& size
>0) {
1215 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1216 return MSVCRT_EINVAL
;
1219 locinfo
= get_locinfo();
1221 locinfo
= locale
->locinfo
;
1223 if(!locinfo
->lc_codepage
) {
1225 if(mbchar
&& size
>0)
1226 memset(mbchar
, 0, size
);
1227 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1228 return MSVCRT_EILSEQ
;
1231 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1232 return MSVCRT_ERANGE
;
1240 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1241 if(!mblen
|| error
) {
1242 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1243 if(mbchar
&& size
>0)
1244 memset(mbchar
, 0, size
);
1246 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1247 return MSVCRT_ERANGE
;
1250 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1251 return MSVCRT_EILSEQ
;
1259 /*********************************************************************
1260 * wctomb_s (MSVCRT.@)
1262 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1264 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1267 /*********************************************************************
1268 * _wctomb_l (MSVCRT.@)
1270 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1274 MSVCRT__wctomb_s_l(&len
, dst
, dst
? 6 : 0, ch
, locale
);
1278 /*********************************************************************
1281 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1283 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1286 /*********************************************************************
1289 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1293 UINT codepage
= get_locinfo()->lc_codepage
;
1297 return (signed char)wchar
;
1300 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1305 /*********************************************************************
1306 * wcrtomb (MSVCRT.@)
1308 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1312 return MSVCRT_wctomb(dst
, ch
);
1315 /*********************************************************************
1316 * iswalnum (MSVCRT.@)
1318 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1320 return isalnumW( wc
);
1323 /*********************************************************************
1324 * iswalpha (MSVCRT.@)
1326 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1328 return isalphaW( wc
);
1331 /*********************************************************************
1332 * iswalpha_l (MSVCRT.@)
1334 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1336 return isalphaW( wc
);
1339 /*********************************************************************
1340 * iswcntrl (MSVCRT.@)
1342 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1344 return iscntrlW( wc
);
1347 /*********************************************************************
1348 * iswdigit (MSVCRT.@)
1350 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1352 return isdigitW( wc
);
1355 /*********************************************************************
1356 * _iswdigit_l (MSVCRT.@)
1358 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1360 return isdigitW( wc
);
1363 /*********************************************************************
1364 * iswgraph (MSVCRT.@)
1366 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1368 return isgraphW( wc
);
1371 /*********************************************************************
1372 * iswlower (MSVCRT.@)
1374 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1376 return islowerW( wc
);
1379 /*********************************************************************
1380 * iswprint (MSVCRT.@)
1382 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1384 return isprintW( wc
);
1387 /*********************************************************************
1388 * iswpunct (MSVCRT.@)
1390 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1392 return ispunctW( wc
);
1395 /*********************************************************************
1396 * iswspace (MSVCRT.@)
1398 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1400 return isspaceW( wc
);
1403 /*********************************************************************
1404 * iswupper (MSVCRT.@)
1406 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1408 return isupperW( wc
);
1411 /*********************************************************************
1412 * iswxdigit (MSVCRT.@)
1414 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1416 return isxdigitW( wc
);
1419 /*********************************************************************
1420 * wcscpy_s (MSVCRT.@)
1422 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1424 MSVCRT_size_t size
= 0;
1426 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1427 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1431 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1433 size
= strlenW(wcSrc
) + 1;
1435 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1436 return MSVCRT_ERANGE
;
1438 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1443 /******************************************************************
1444 * wcsncpy (MSVCRT.@)
1446 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1447 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1452 if(!(s1
[i
] = s2
[i
])) break;
1458 /******************************************************************
1459 * wcsncpy_s (MSVCRT.@)
1461 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1462 MSVCRT_size_t count
)
1465 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1467 if(!wcDest
&& !numElement
&& !count
)
1470 if (!wcDest
|| !numElement
)
1471 return MSVCRT_EINVAL
;
1476 return count
? MSVCRT_EINVAL
: 0;
1479 while (numElement
&& count
&& *wcSrc
)
1485 if (!numElement
&& truncate
)
1488 return MSVCRT_STRUNCATE
;
1490 else if (!numElement
)
1493 return MSVCRT_ERANGE
;
1500 /******************************************************************
1501 * wcscat_s (MSVCRT.@)
1504 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
1506 MSVCRT_wchar_t
* ptr
= dst
;
1508 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
1512 return MSVCRT_EINVAL
;
1515 /* seek to end of dst string (or elem if no end of string is found */
1516 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
1517 while (ptr
< dst
+ elem
)
1519 if ((*ptr
++ = *src
++) == '\0') return 0;
1521 /* not enough space */
1523 return MSVCRT_ERANGE
;
1526 /*********************************************************************
1527 * wcsncat_s (MSVCRT.@)
1530 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
1531 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
1533 MSVCRT_size_t srclen
;
1534 MSVCRT_wchar_t dststart
;
1537 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1538 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
1539 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
1544 for (dststart
= 0; dststart
< elem
; dststart
++)
1546 if (dst
[dststart
] == '\0')
1549 if (dststart
== elem
)
1551 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
1552 return MSVCRT_EINVAL
;
1555 if (count
== MSVCRT__TRUNCATE
)
1557 srclen
= strlenW(src
);
1558 if (srclen
>= (elem
- dststart
))
1560 srclen
= elem
- dststart
- 1;
1561 ret
= MSVCRT_STRUNCATE
;
1565 srclen
= min(strlenW(src
), count
);
1566 if (srclen
< (elem
- dststart
))
1568 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
1569 dst
[dststart
+srclen
] = '\0';
1572 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
1574 return MSVCRT_ERANGE
;
1577 /*********************************************************************
1578 * _wcstoi64_l (MSVCRT.@)
1580 * FIXME: locale parameter is ignored
1582 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
1583 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1585 BOOL negative
= FALSE
;
1588 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1590 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1591 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1592 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1594 while(isspaceW(*nptr
)) nptr
++;
1599 } else if(*nptr
== '+')
1602 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1615 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1623 if(cur
<'a' || cur
>='a'+base
-10)
1633 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
1634 ret
= MSVCRT_I64_MAX
;
1635 *MSVCRT__errno() = MSVCRT_ERANGE
;
1636 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
1637 ret
= MSVCRT_I64_MIN
;
1638 *MSVCRT__errno() = MSVCRT_ERANGE
;
1644 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1649 /*********************************************************************
1650 * _wcstoi64 (MSVCRT.@)
1652 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
1653 MSVCRT_wchar_t
**endptr
, int base
)
1655 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
1658 /*********************************************************************
1659 * _wcstol_l (MSVCRT.@)
1661 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
1662 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1664 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
1666 if(ret
> MSVCRT_LONG_MAX
) {
1667 ret
= MSVCRT_LONG_MAX
;
1668 *MSVCRT__errno() = MSVCRT_ERANGE
;
1669 }else if(ret
< MSVCRT_LONG_MIN
) {
1670 ret
= MSVCRT_LONG_MIN
;
1671 *MSVCRT__errno() = MSVCRT_ERANGE
;
1676 /*********************************************************************
1677 * _wtoi_l (MSVCRT.@)
1679 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1681 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1685 *MSVCRT__errno() = MSVCRT_ERANGE
;
1686 } else if(ret
< INT_MIN
) {
1688 *MSVCRT__errno() = MSVCRT_ERANGE
;
1693 /*********************************************************************
1696 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
1698 return MSVCRT__wtoi_l(str
, NULL
);
1701 /*********************************************************************
1702 * _wtol_l (MSVCRT.@)
1704 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1706 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1708 if(ret
> MSVCRT_LONG_MAX
) {
1709 ret
= MSVCRT_LONG_MAX
;
1710 *MSVCRT__errno() = MSVCRT_ERANGE
;
1711 } else if(ret
< MSVCRT_LONG_MIN
) {
1712 ret
= MSVCRT_LONG_MIN
;
1713 *MSVCRT__errno() = MSVCRT_ERANGE
;
1718 /*********************************************************************
1721 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
1723 return MSVCRT__wtol_l(str
, NULL
);
1726 /*********************************************************************
1727 * _wcstoui64_l (MSVCRT.@)
1729 * FIXME: locale parameter is ignored
1731 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
1732 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1734 BOOL negative
= FALSE
;
1735 unsigned __int64 ret
= 0;
1737 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1739 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1740 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1741 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1743 while(isspaceW(*nptr
)) nptr
++;
1748 } else if(*nptr
== '+')
1751 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1764 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1772 if(cur
<'a' || cur
>='a'+base
-10)
1779 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
1780 ret
= MSVCRT_UI64_MAX
;
1781 *MSVCRT__errno() = MSVCRT_ERANGE
;
1787 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1789 return negative
? -ret
: ret
;
1792 /*********************************************************************
1793 * _wcstoui64 (MSVCRT.@)
1795 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
1796 MSVCRT_wchar_t
**endptr
, int base
)
1798 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
1801 /*********************************************************************
1802 * _wcstoul_l (MSVCRT.@)
1804 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
1805 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1807 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
1809 if(ret
> MSVCRT_ULONG_MAX
) {
1810 ret
= MSVCRT_ULONG_MAX
;
1811 *MSVCRT__errno() = MSVCRT_ERANGE
;
1816 /*********************************************************************
1817 * wcstoul (MSVCRT.@)
1819 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
1821 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
1824 /******************************************************************
1825 * wcsnlen (MSVCRT.@)
1827 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
1831 for (i
= 0; i
< maxlen
; i
++)
1836 /*********************************************************************
1837 * _towupper_l (MSVCRT.@)
1839 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1844 /*********************************************************************
1845 * towupper (MSVCRT.@)
1847 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
1849 return MSVCRT__towupper_l(c
, NULL
);
1852 /*********************************************************************
1853 * _towlower_l (MSVCRT.@)
1855 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1860 /*********************************************************************
1861 * towlower (MSVCRT.@)
1863 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
1865 return MSVCRT__towlower_l(c
, NULL
);
1868 /*********************************************************************
1871 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
1873 return strchrW(str
, ch
);
1876 /***********************************************************************
1879 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
1881 return strlenW(str
);
1884 /*********************************************************************
1887 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
1889 return strstrW(str
, sub
);
1892 /*********************************************************************
1893 * _wtoi64_l (MSVCRT.@)
1895 __int64 CDECL
_wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1897 ULONGLONG RunningTotal
= 0;
1900 while (isspaceW(*str
)) {
1906 } else if (*str
== '-') {
1911 while (*str
>= '0' && *str
<= '9') {
1912 RunningTotal
= RunningTotal
* 10 + *str
- '0';
1916 return bMinus
? -RunningTotal
: RunningTotal
;
1919 /*********************************************************************
1920 * _wtoi64 (MSVCRT.@)
1922 __int64 CDECL
_wtoi64(const MSVCRT_wchar_t
*str
)
1924 return _wtoi64_l(str
, NULL
);
1927 /*********************************************************************
1928 * wcsncmp (MSVCRT.@)
1930 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
1932 return strncmpW(str1
, str2
, n
);