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 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
109 return strcmpiW(str1
, str2
);
110 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
111 str1
, -1, str2
, -1)-CSTR_EQUAL
;
114 /*********************************************************************
115 * _wcsicoll (MSVCRT.@)
117 INT CDECL
MSVCRT__wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
119 return MSVCRT__wcsicoll_l(str1
, str2
, NULL
);
122 /*********************************************************************
123 * _wcsnicoll_l (MSVCRT.@)
125 int CDECL
MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
126 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
128 MSVCRT_pthreadlocinfo locinfo
;
131 locinfo
= get_locinfo();
133 locinfo
= locale
->locinfo
;
135 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
136 return strncmpiW(str1
, str2
, count
);
137 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
138 str1
, count
, str2
, count
)-CSTR_EQUAL
;
141 /*********************************************************************
142 * _wcsnicoll (MSVCRT.@)
144 INT CDECL
MSVCRT__wcsnicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
146 return MSVCRT__wcsnicoll_l(str1
, str2
, count
, NULL
);
149 /*********************************************************************
150 * _wcsnset (MSVCRT.@)
152 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
154 MSVCRT_wchar_t
* ret
= str
;
155 while ((n
-- > 0) && *str
) *str
++ = c
;
159 /*********************************************************************
162 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsrev( MSVCRT_wchar_t
* str
)
164 MSVCRT_wchar_t
* ret
= str
;
165 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
168 MSVCRT_wchar_t t
= *end
;
175 /*********************************************************************
178 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
180 MSVCRT_wchar_t
* ret
= str
;
181 while (*str
) *str
++ = c
;
185 /******************************************************************
186 * _wcsupr_s_l (MSVCRT.@)
188 int CDECL
MSVCRT__wcsupr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
,
189 MSVCRT__locale_t locale
)
191 MSVCRT_wchar_t
* ptr
= str
;
195 if (str
) *str
= '\0';
196 *MSVCRT__errno() = MSVCRT_EINVAL
;
197 return MSVCRT_EINVAL
;
203 /* FIXME: add locale support */
204 *ptr
= toupperW(*ptr
);
208 /* MSDN claims that the function should return and set errno to
209 * ERANGE, which doesn't seem to be true based on the tests. */
211 *MSVCRT__errno() = MSVCRT_EINVAL
;
212 return MSVCRT_EINVAL
;
215 /******************************************************************
216 * _wcsupr_s (MSVCRT.@)
219 INT CDECL
MSVCRT__wcsupr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
221 return MSVCRT__wcsupr_s_l( str
, n
, NULL
);
224 /******************************************************************
225 * _wcslwr_s (MSVCRT.@)
227 int CDECL
MSVCRT__wcslwr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
229 MSVCRT_wchar_t
* ptr
= str
;
233 if (str
) *str
= '\0';
234 *MSVCRT__errno() = MSVCRT_EINVAL
;
235 return MSVCRT_EINVAL
;
241 *ptr
= tolowerW(*ptr
);
245 /* MSDN claims that the function should return and set errno to
246 * ERANGE, which doesn't seem to be true based on the tests. */
248 *MSVCRT__errno() = MSVCRT_EINVAL
;
249 return MSVCRT_EINVAL
;
252 /*********************************************************************
253 * _wcsncoll_l (MSVCRT.@)
255 int CDECL
MSVCRT__wcsncoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
256 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
258 MSVCRT_pthreadlocinfo locinfo
;
261 locinfo
= get_locinfo();
263 locinfo
= locale
->locinfo
;
265 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
266 return strncmpW(str1
, str2
, count
);
267 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, count
, str2
, count
)-CSTR_EQUAL
;
270 /*********************************************************************
271 * _wcsncoll (MSVCRT.@)
273 int CDECL
MSVCRT__wcsncoll(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
275 return MSVCRT__wcsncoll_l(str1
, str2
, count
, NULL
);
278 /*********************************************************************
279 * _wcstod_l (MSVCRT.@)
281 double CDECL
MSVCRT__wcstod_l(const MSVCRT_wchar_t
* str
, MSVCRT_wchar_t
** end
,
282 MSVCRT__locale_t locale
)
284 MSVCRT_pthreadlocinfo locinfo
;
285 unsigned __int64 d
=0, hlp
;
288 const MSVCRT_wchar_t
*p
;
290 long double lret
=1, expcnt
= 10;
291 BOOL found_digit
= FALSE
, negexp
;
293 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
296 locinfo
= get_locinfo();
298 locinfo
= locale
->locinfo
;
310 while(isdigitW(*p
)) {
312 hlp
= d
*10+*(p
++)-'0';
313 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
319 while(isdigitW(*p
)) {
323 if(*p
== *locinfo
->lconv
->decimal_point
)
326 while(isdigitW(*p
)) {
328 hlp
= d
*10+*(p
++)-'0';
329 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
340 *end
= (MSVCRT_wchar_t
*)str
;
344 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
355 while(isdigitW(*p
)) {
356 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
362 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
363 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
366 if(*p
=='-' || *p
=='+')
372 fpcontrol
= _control87(0, 0);
373 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
374 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
383 expcnt
= expcnt
*expcnt
;
385 ret
= (long double)sign
* (negexp
? d
/lret
: d
*lret
);
387 _control87(fpcontrol
, 0xffffffff);
389 if((d
&& ret
==0.0) || isinf(ret
))
390 *MSVCRT__errno() = MSVCRT_ERANGE
;
393 *end
= (MSVCRT_wchar_t
*)p
;
398 /*********************************************************************
399 * wcsrtombs_l (INTERNAL)
401 static MSVCRT_size_t
MSVCRT_wcsrtombs_l(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
402 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
404 MSVCRT_pthreadlocinfo locinfo
;
405 MSVCRT_size_t tmp
= 0;
409 locinfo
= get_locinfo();
411 locinfo
= locale
->locinfo
;
414 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
415 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
416 if(!tmp
|| used_default
) {
417 *MSVCRT__errno() = MSVCRT_EILSEQ
;
425 MSVCRT_size_t i
, size
;
427 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
428 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
429 if(!size
|| used_default
) {
430 *MSVCRT__errno() = MSVCRT_EILSEQ
;
436 for(i
=0; i
<size
; i
++)
437 mbstr
[tmp
++] = buf
[i
];
448 /*********************************************************************
449 * _wcstombs_l (MSVCRT.@)
451 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
452 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
454 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
457 /*********************************************************************
458 * wcstombs (MSVCRT.@)
460 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
463 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
466 /*********************************************************************
467 * wcsrtombs (MSVCRT.@)
469 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
470 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
475 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
478 /*********************************************************************
479 * MSVCRT_wcsrtombs_s_l (INTERNAL)
481 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
482 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
483 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
487 if(!mbstr
&& !size
&& wcstr
) {
488 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
490 return *MSVCRT__errno();
496 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
497 if (size
) mbstr
[0] = '\0';
498 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
499 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
501 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
506 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
510 return *MSVCRT__errno();
511 }else if(conv
< size
)
512 mbstr
[conv
++] = '\0';
513 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
514 mbstr
[conv
-1] = '\0';
516 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
519 return MSVCRT_ERANGE
;
527 /*********************************************************************
528 * _wcstombs_s_l (MSVCRT.@)
530 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
531 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
532 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
534 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
537 /*********************************************************************
538 * wcstombs_s (MSVCRT.@)
540 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
541 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
543 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
546 /*********************************************************************
547 * wcsrtombs_s (MSVCRT.@)
549 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
550 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
555 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
558 /*********************************************************************
561 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
563 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
566 /*********************************************************************
569 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
571 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
574 /*********************************************************************
577 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
579 return MSVCRT__wcstod_l(str
, NULL
, locale
);
582 /*********************************************************************
583 * arg_clbk_valist (INTERNAL)
585 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
590 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
591 else if(type
== VT_INT
)
592 ret
.get_int
= va_arg(*valist
, int);
593 else if(type
== VT_R8
)
594 ret
.get_double
= va_arg(*valist
, double);
595 else if(type
== VT_PTR
)
596 ret
.get_ptr
= va_arg(*valist
, void*);
598 ERR("Incorrect type\n");
605 /*********************************************************************
606 * arg_clbk_positional (INTERNAL)
608 static printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
610 printf_arg
*args
= ctx
;
614 /*********************************************************************
615 * _vsnprintf (MSVCRT.@)
617 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
618 const char *format
, __ms_va_list valist
)
620 static const char nullbyte
= '\0';
621 struct _str_ctx_a ctx
= {len
, str
};
624 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, FALSE
, FALSE
,
625 arg_clbk_valist
, NULL
, &valist
);
626 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
630 /*********************************************************************
631 * _vsnprintf_l (MSVCRT.@)
633 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
634 MSVCRT__locale_t locale
, __ms_va_list valist
)
636 static const char nullbyte
= '\0';
637 struct _str_ctx_a ctx
= {len
, str
};
640 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, FALSE
,
641 arg_clbk_valist
, NULL
, &valist
);
642 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
646 /*********************************************************************
647 * _vsprintf_l (MSVCRT.@)
649 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
650 MSVCRT__locale_t locale
, __ms_va_list valist
)
652 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
655 /*********************************************************************
656 * _sprintf_l (MSVCRT.@)
658 int CDECL
MSVCRT_sprintf_l(char *str
, const char *format
,
659 MSVCRT__locale_t locale
, ...)
663 __ms_va_start(valist
, locale
);
664 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
669 /*********************************************************************
670 * _vsnprintf_s_l (MSVCRT.@)
672 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
673 MSVCRT_size_t count
, const char *format
,
674 MSVCRT__locale_t locale
, __ms_va_list valist
)
676 static const char nullbyte
= '\0';
677 struct _str_ctx_a ctx
;
680 if(sizeOfBuffer
<count
+1 || count
==-1)
687 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, TRUE
,
688 arg_clbk_valist
, NULL
, &valist
);
689 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
691 if(ret
<0 || ret
==len
) {
692 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
693 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
694 memset(str
, 0, sizeOfBuffer
);
704 /*********************************************************************
705 * _vsprintf_s_l (MSVCRT.@)
707 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
708 MSVCRT__locale_t locale
, __ms_va_list valist
)
710 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
713 /*********************************************************************
714 * _sprintf_s_l (MSVCRT.@)
716 int CDECL
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
717 MSVCRT__locale_t locale
, ...)
721 __ms_va_start(valist
, locale
);
722 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
727 /*********************************************************************
728 * _vsnprintf_s (MSVCRT.@)
730 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
731 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
733 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
736 /*********************************************************************
737 * vsprintf (MSVCRT.@)
739 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
741 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
744 /*********************************************************************
745 * vsprintf_s (MSVCRT.@)
747 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
749 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
752 /*********************************************************************
753 * _vscprintf (MSVCRT.@)
755 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
757 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
760 /*********************************************************************
761 * _snprintf (MSVCRT.@)
763 int CDECL
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
767 __ms_va_start(valist
, format
);
768 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
773 /*********************************************************************
774 * _snprintf_s (MSVCRT.@)
776 int CDECL
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
777 const char *format
, ...)
781 __ms_va_start(valist
, format
);
782 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
787 /*********************************************************************
788 * _scprintf (MSVCRT.@)
790 int CDECL
MSVCRT__scprintf(const char *format
, ...)
794 __ms_va_start(valist
, format
);
795 retval
= MSVCRT__vscprintf(format
, valist
);
800 /*********************************************************************
801 * _vsnwprintf (MSVCRT.@)
803 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
804 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
806 static const MSVCRT_wchar_t nullbyte
= '\0';
807 struct _str_ctx_w ctx
= {len
, str
};
810 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, FALSE
, FALSE
,
811 arg_clbk_valist
, NULL
, &valist
);
812 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
816 /*********************************************************************
817 * _vsnwprintf_l (MSVCRT.@)
819 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
820 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
823 static const MSVCRT_wchar_t nullbyte
= '\0';
824 struct _str_ctx_w ctx
= {len
, str
};
827 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, FALSE
,
828 arg_clbk_valist
, NULL
, &valist
);
829 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
833 /*********************************************************************
834 * _vswprintf_p_l (MSVCRT.@)
836 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
837 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
839 static const MSVCRT_wchar_t nullbyte
= '\0';
840 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
841 struct _str_ctx_w puts_ctx
= {length
, buffer
};
844 memset(args_ctx
, 0, sizeof(args_ctx
));
846 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
848 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
849 *MSVCRT__errno() = MSVCRT_EINVAL
;
852 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
853 arg_clbk_valist
, NULL
, &args
);
855 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
856 arg_clbk_positional
, args_ctx
, NULL
);
858 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
862 /*********************************************************************
863 * _vsnwprintf_s_l (MSVCRT.@)
865 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
866 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
867 MSVCRT__locale_t locale
, __ms_va_list valist
)
869 static const MSVCRT_wchar_t nullbyte
= '\0';
870 struct _str_ctx_w ctx
;
874 if(count
!=-1 && len
>count
+1)
879 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, TRUE
,
880 arg_clbk_valist
, NULL
, &valist
);
881 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
883 if(ret
<0 || ret
==len
) {
884 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
885 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
886 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
896 /*********************************************************************
897 * _vsnwprintf_s (MSVCRT.@)
899 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
900 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
902 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
903 format
, NULL
, valist
);
906 /*********************************************************************
907 * _snwprintf (MSVCRT.@)
909 int CDECL
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
913 __ms_va_start(valist
, format
);
914 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
919 /*********************************************************************
920 * _snwprintf_l (MSVCRT.@)
922 int CDECL
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
923 MSVCRT__locale_t locale
, ...)
927 __ms_va_start(valist
, locale
);
928 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
933 /*********************************************************************
934 * _snwprintf_s (MSVCRT.@)
936 int CDECL
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
937 const MSVCRT_wchar_t
*format
, ...)
941 __ms_va_start(valist
, format
);
942 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
947 /*********************************************************************
948 * _snwprintf_s_l (MSVCRT.@)
950 int CDECL
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
951 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
955 __ms_va_start(valist
, locale
);
956 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
961 /*********************************************************************
964 int CDECL
MSVCRT_sprintf( char *str
, const char *format
, ... )
969 __ms_va_start( ap
, format
);
970 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
975 /*********************************************************************
976 * sprintf_s (MSVCRT.@)
978 int CDECL
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
983 __ms_va_start( ap
, format
);
984 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
989 /*********************************************************************
990 * _scwprintf (MSVCRT.@)
992 int CDECL
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
997 __ms_va_start( ap
, format
);
998 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1003 /*********************************************************************
1004 * swprintf (MSVCRT.@)
1006 int CDECL
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1011 __ms_va_start( ap
, format
);
1012 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1017 /*********************************************************************
1018 * swprintf_s (MSVCRT.@)
1020 int CDECL
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1021 const MSVCRT_wchar_t
*format
, ... )
1026 __ms_va_start(ap
, format
);
1027 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1033 /*********************************************************************
1034 * _swprintf_s_l (MSVCRT.@)
1036 int CDECL
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1037 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1042 __ms_va_start(ap
, locale
);
1043 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1049 /*********************************************************************
1050 * _vswprintf (MSVCRT.@)
1052 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1054 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1057 /*********************************************************************
1058 * _vswprintf (MSVCRT.@)
1060 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1061 MSVCRT__locale_t locale
, __ms_va_list args
)
1063 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1066 /*********************************************************************
1067 * _vscwprintf (MSVCRT.@)
1069 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1071 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1074 /*********************************************************************
1075 * _vscwprintf_l (MSVCRT.@)
1077 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1079 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1082 /*********************************************************************
1083 * _vscwprintf_p_l (MSVCRT.@)
1085 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1087 return MSVCRT_vswprintf_p_l( NULL
, INT_MAX
, format
, locale
, args
);
1090 /*********************************************************************
1091 * vswprintf_s (MSVCRT.@)
1093 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1094 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1096 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1099 /*********************************************************************
1100 * _vswprintf_s_l (MSVCRT.@)
1102 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1103 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1105 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1106 format
, locale
, args
);
1109 /*********************************************************************
1110 * _vsprintf_p_l (MSVCRT.@)
1112 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1113 MSVCRT__locale_t locale
, __ms_va_list args
)
1115 static const char nullbyte
= '\0';
1116 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1117 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1120 memset(args_ctx
, 0, sizeof(args_ctx
));
1122 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1124 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1125 *MSVCRT__errno() = MSVCRT_EINVAL
;
1128 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
1129 arg_clbk_valist
, NULL
, &args
);
1131 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
1132 arg_clbk_positional
, args_ctx
, NULL
);
1134 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1138 /*********************************************************************
1139 * _vsprintf_p (MSVCRT.@)
1141 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1142 const char *format
, __ms_va_list args
)
1144 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1147 /*********************************************************************
1148 * _sprintf_p_l (MSVCRT.@)
1150 int CDECL
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1151 const char *format
, MSVCRT__locale_t locale
, ...)
1153 __ms_va_list valist
;
1156 __ms_va_start(valist
, locale
);
1157 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1158 __ms_va_end(valist
);
1163 /*********************************************************************
1164 * _swprintf_p_l (MSVCRT.@)
1166 int CDECL
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1167 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1169 __ms_va_list valist
;
1172 __ms_va_start(valist
, locale
);
1173 r
= MSVCRT_vswprintf_p_l(buffer
, length
, format
, locale
, valist
);
1174 __ms_va_end(valist
);
1179 /*********************************************************************
1180 * _wcscoll_l (MSVCRT.@)
1182 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1184 MSVCRT_pthreadlocinfo locinfo
;
1187 locinfo
= get_locinfo();
1189 locinfo
= locale
->locinfo
;
1191 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1192 return strcmpW(str1
, str2
);
1193 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1196 /*********************************************************************
1197 * wcscoll (MSVCRT.@)
1199 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1201 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1204 /*********************************************************************
1205 * wcspbrk (MSVCRT.@)
1207 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1209 const MSVCRT_wchar_t
* p
;
1213 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1219 /*********************************************************************
1220 * wcstok_s (MSVCRT.@)
1222 MSVCRT_wchar_t
* CDECL
wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1223 MSVCRT_wchar_t
**next_token
)
1225 MSVCRT_wchar_t
*ret
;
1227 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1228 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1229 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1231 if (!str
) str
= *next_token
;
1233 while (*str
&& strchrW( delim
, *str
)) str
++;
1234 if (!*str
) return NULL
;
1236 while (*str
&& !strchrW( delim
, *str
)) str
++;
1237 if (*str
) *str
++ = 0;
1242 /*********************************************************************
1245 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1247 return wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1250 /*********************************************************************
1251 * _wctomb_s_l (MSVCRT.@)
1253 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1254 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1256 MSVCRT_pthreadlocinfo locinfo
;
1260 if(!mbchar
&& size
>0) {
1269 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1270 return MSVCRT_EINVAL
;
1273 locinfo
= get_locinfo();
1275 locinfo
= locale
->locinfo
;
1277 if(!locinfo
->lc_codepage
) {
1279 if(mbchar
&& size
>0)
1280 memset(mbchar
, 0, size
);
1281 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1282 return MSVCRT_EILSEQ
;
1285 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1286 return MSVCRT_ERANGE
;
1294 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1295 if(!mblen
|| error
) {
1296 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1297 if(mbchar
&& size
>0)
1298 memset(mbchar
, 0, size
);
1300 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1301 return MSVCRT_ERANGE
;
1304 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1305 return MSVCRT_EILSEQ
;
1313 /*********************************************************************
1314 * wctomb_s (MSVCRT.@)
1316 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1318 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1321 /*********************************************************************
1322 * _wctomb_l (MSVCRT.@)
1324 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1328 MSVCRT__wctomb_s_l(&len
, dst
, dst
? 6 : 0, ch
, locale
);
1332 /*********************************************************************
1335 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1337 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1340 /*********************************************************************
1343 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1347 UINT codepage
= get_locinfo()->lc_codepage
;
1351 return (signed char)wchar
;
1354 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1359 /*********************************************************************
1360 * wcrtomb (MSVCRT.@)
1362 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1366 return MSVCRT_wctomb(dst
, ch
);
1369 /*********************************************************************
1370 * iswalnum (MSVCRT.@)
1372 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1374 return isalnumW( wc
);
1377 /*********************************************************************
1378 * iswalpha (MSVCRT.@)
1380 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1382 return isalphaW( wc
);
1385 /*********************************************************************
1386 * iswalpha_l (MSVCRT.@)
1388 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1390 return isalphaW( wc
);
1393 /*********************************************************************
1394 * iswcntrl (MSVCRT.@)
1396 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1398 return iscntrlW( wc
);
1401 /*********************************************************************
1402 * iswdigit (MSVCRT.@)
1404 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1406 return isdigitW( wc
);
1409 /*********************************************************************
1410 * _iswdigit_l (MSVCRT.@)
1412 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1414 return isdigitW( wc
);
1417 /*********************************************************************
1418 * iswgraph (MSVCRT.@)
1420 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1422 return isgraphW( wc
);
1425 /*********************************************************************
1426 * iswlower (MSVCRT.@)
1428 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1430 return islowerW( wc
);
1433 /*********************************************************************
1434 * iswprint (MSVCRT.@)
1436 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1438 return isprintW( wc
);
1441 /*********************************************************************
1442 * iswpunct (MSVCRT.@)
1444 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1446 return ispunctW( wc
);
1449 /*********************************************************************
1450 * iswspace (MSVCRT.@)
1452 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1454 return isspaceW( wc
);
1457 /*********************************************************************
1458 * iswupper (MSVCRT.@)
1460 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1462 return isupperW( wc
);
1465 /*********************************************************************
1466 * iswxdigit (MSVCRT.@)
1468 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1470 return isxdigitW( wc
);
1473 /*********************************************************************
1474 * wcscpy_s (MSVCRT.@)
1476 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1478 MSVCRT_size_t size
= 0;
1480 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1481 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1485 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1487 size
= strlenW(wcSrc
) + 1;
1489 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1490 return MSVCRT_ERANGE
;
1492 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1497 /******************************************************************
1498 * wcsncpy (MSVCRT.@)
1500 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1501 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1506 if(!(s1
[i
] = s2
[i
])) break;
1512 /******************************************************************
1513 * wcsncpy_s (MSVCRT.@)
1515 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1516 MSVCRT_size_t count
)
1519 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1521 if(!wcDest
&& !numElement
&& !count
)
1524 if (!wcDest
|| !numElement
)
1525 return MSVCRT_EINVAL
;
1530 return count
? MSVCRT_EINVAL
: 0;
1533 while (numElement
&& count
&& *wcSrc
)
1539 if (!numElement
&& truncate
)
1542 return MSVCRT_STRUNCATE
;
1544 else if (!numElement
)
1547 return MSVCRT_ERANGE
;
1554 /******************************************************************
1555 * wcscat_s (MSVCRT.@)
1558 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
1560 MSVCRT_wchar_t
* ptr
= dst
;
1562 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
1566 return MSVCRT_EINVAL
;
1569 /* seek to end of dst string (or elem if no end of string is found */
1570 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
1571 while (ptr
< dst
+ elem
)
1573 if ((*ptr
++ = *src
++) == '\0') return 0;
1575 /* not enough space */
1577 return MSVCRT_ERANGE
;
1580 /*********************************************************************
1581 * wcsncat_s (MSVCRT.@)
1584 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
1585 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
1587 MSVCRT_size_t srclen
;
1588 MSVCRT_wchar_t dststart
;
1591 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1592 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
1593 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
1598 for (dststart
= 0; dststart
< elem
; dststart
++)
1600 if (dst
[dststart
] == '\0')
1603 if (dststart
== elem
)
1605 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
1606 return MSVCRT_EINVAL
;
1609 if (count
== MSVCRT__TRUNCATE
)
1611 srclen
= strlenW(src
);
1612 if (srclen
>= (elem
- dststart
))
1614 srclen
= elem
- dststart
- 1;
1615 ret
= MSVCRT_STRUNCATE
;
1619 srclen
= min(strlenW(src
), count
);
1620 if (srclen
< (elem
- dststart
))
1622 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
1623 dst
[dststart
+srclen
] = '\0';
1626 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
1628 return MSVCRT_ERANGE
;
1631 /*********************************************************************
1632 * _wcstoi64_l (MSVCRT.@)
1634 * FIXME: locale parameter is ignored
1636 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
1637 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1639 BOOL negative
= FALSE
;
1642 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1644 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1645 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1646 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1648 while(isspaceW(*nptr
)) nptr
++;
1653 } else if(*nptr
== '+')
1656 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1669 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1677 if(cur
<'a' || cur
>='a'+base
-10)
1687 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
1688 ret
= MSVCRT_I64_MAX
;
1689 *MSVCRT__errno() = MSVCRT_ERANGE
;
1690 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
1691 ret
= MSVCRT_I64_MIN
;
1692 *MSVCRT__errno() = MSVCRT_ERANGE
;
1698 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1703 /*********************************************************************
1704 * _wcstoi64 (MSVCRT.@)
1706 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
1707 MSVCRT_wchar_t
**endptr
, int base
)
1709 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
1712 /*********************************************************************
1713 * _wcstol_l (MSVCRT.@)
1715 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
1716 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1718 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
1720 if(ret
> MSVCRT_LONG_MAX
) {
1721 ret
= MSVCRT_LONG_MAX
;
1722 *MSVCRT__errno() = MSVCRT_ERANGE
;
1723 }else if(ret
< MSVCRT_LONG_MIN
) {
1724 ret
= MSVCRT_LONG_MIN
;
1725 *MSVCRT__errno() = MSVCRT_ERANGE
;
1730 /*********************************************************************
1731 * _wtoi_l (MSVCRT.@)
1733 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1735 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1739 *MSVCRT__errno() = MSVCRT_ERANGE
;
1740 } else if(ret
< INT_MIN
) {
1742 *MSVCRT__errno() = MSVCRT_ERANGE
;
1747 /*********************************************************************
1750 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
1752 return MSVCRT__wtoi_l(str
, NULL
);
1755 /*********************************************************************
1756 * _wtol_l (MSVCRT.@)
1758 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1760 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1762 if(ret
> MSVCRT_LONG_MAX
) {
1763 ret
= MSVCRT_LONG_MAX
;
1764 *MSVCRT__errno() = MSVCRT_ERANGE
;
1765 } else if(ret
< MSVCRT_LONG_MIN
) {
1766 ret
= MSVCRT_LONG_MIN
;
1767 *MSVCRT__errno() = MSVCRT_ERANGE
;
1772 /*********************************************************************
1775 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
1777 return MSVCRT__wtol_l(str
, NULL
);
1780 /*********************************************************************
1781 * _wcstoui64_l (MSVCRT.@)
1783 * FIXME: locale parameter is ignored
1785 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
1786 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1788 BOOL negative
= FALSE
;
1789 unsigned __int64 ret
= 0;
1791 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1793 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1794 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1795 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1797 while(isspaceW(*nptr
)) nptr
++;
1802 } else if(*nptr
== '+')
1805 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1818 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1826 if(cur
<'a' || cur
>='a'+base
-10)
1833 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
1834 ret
= MSVCRT_UI64_MAX
;
1835 *MSVCRT__errno() = MSVCRT_ERANGE
;
1841 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1843 return negative
? -ret
: ret
;
1846 /*********************************************************************
1847 * _wcstoui64 (MSVCRT.@)
1849 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
1850 MSVCRT_wchar_t
**endptr
, int base
)
1852 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
1855 /*********************************************************************
1856 * _wcstoul_l (MSVCRT.@)
1858 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
1859 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1861 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
1863 if(ret
> MSVCRT_ULONG_MAX
) {
1864 ret
= MSVCRT_ULONG_MAX
;
1865 *MSVCRT__errno() = MSVCRT_ERANGE
;
1870 /*********************************************************************
1871 * wcstoul (MSVCRT.@)
1873 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
1875 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
1878 /******************************************************************
1879 * wcsnlen (MSVCRT.@)
1881 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
1885 for (i
= 0; i
< maxlen
; i
++)
1890 /*********************************************************************
1891 * _towupper_l (MSVCRT.@)
1893 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1898 /*********************************************************************
1899 * towupper (MSVCRT.@)
1901 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
1903 return MSVCRT__towupper_l(c
, NULL
);
1906 /*********************************************************************
1907 * _towlower_l (MSVCRT.@)
1909 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1914 /*********************************************************************
1915 * towlower (MSVCRT.@)
1917 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
1919 return MSVCRT__towlower_l(c
, NULL
);
1922 /*********************************************************************
1925 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
1927 return strchrW(str
, ch
);
1930 /***********************************************************************
1933 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
1935 return strlenW(str
);
1938 /*********************************************************************
1941 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
1943 return strstrW(str
, sub
);
1946 /*********************************************************************
1947 * _wtoi64_l (MSVCRT.@)
1949 __int64 CDECL
_wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1951 ULONGLONG RunningTotal
= 0;
1952 BOOL bMinus
= FALSE
;
1954 while (isspaceW(*str
)) {
1960 } else if (*str
== '-') {
1965 while (*str
>= '0' && *str
<= '9') {
1966 RunningTotal
= RunningTotal
* 10 + *str
- '0';
1970 return bMinus
? -RunningTotal
: RunningTotal
;
1973 /*********************************************************************
1974 * _wtoi64 (MSVCRT.@)
1976 __int64 CDECL
_wtoi64(const MSVCRT_wchar_t
*str
)
1978 return _wtoi64_l(str
, NULL
);
1981 /*********************************************************************
1982 * wcsncmp (MSVCRT.@)
1984 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
1986 return strncmpW(str1
, str2
, n
);