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 /*********************************************************************
44 * _get_printf_count_output (MSVCR80.@)
46 int CDECL
MSVCRT__get_printf_count_output( void )
48 return n_format_enabled
? 1 : 0;
51 /*********************************************************************
52 * _set_printf_count_output (MSVCR80.@)
54 int CDECL
MSVCRT__set_printf_count_output( int enable
)
56 BOOL old
= n_format_enabled
;
57 n_format_enabled
= enable
!= 0;
61 /*********************************************************************
64 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsdup( const MSVCRT_wchar_t
* str
)
66 MSVCRT_wchar_t
* ret
= NULL
;
69 int size
= (strlenW(str
) + 1) * sizeof(MSVCRT_wchar_t
);
70 ret
= MSVCRT_malloc( size
);
71 if (ret
) memcpy( ret
, str
, size
);
76 INT CDECL
MSVCRT__wcsicmp_l(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, MSVCRT__locale_t locale
)
78 if(!MSVCRT_CHECK_PMT(str1
!= NULL
) || !MSVCRT_CHECK_PMT(str2
!= NULL
))
79 return MSVCRT__NLSCMPERROR
;
81 return strcmpiW(str1
, str2
);
84 /*********************************************************************
87 INT CDECL
MSVCRT__wcsicmp( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
89 return strcmpiW( str1
, str2
);
92 /*********************************************************************
93 * _wcsnicmp_l (MSVCRT.@)
95 INT CDECL
MSVCRT__wcsnicmp_l(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
, MSVCRT__locale_t locale
)
97 return strncmpiW(str1
, str2
, n
);
100 /*********************************************************************
101 * _wcsnicmp (MSVCRT.@)
103 INT CDECL
MSVCRT__wcsnicmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
)
105 return MSVCRT__wcsnicmp_l(str1
, str2
, n
, NULL
);
108 /*********************************************************************
109 * _wcsicoll_l (MSVCRT.@)
111 int CDECL
MSVCRT__wcsicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
113 MSVCRT_pthreadlocinfo locinfo
;
116 locinfo
= get_locinfo();
118 locinfo
= locale
->locinfo
;
120 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
121 return strcmpiW(str1
, str2
);
122 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
123 str1
, -1, str2
, -1)-CSTR_EQUAL
;
126 /*********************************************************************
127 * _wcsicoll (MSVCRT.@)
129 INT CDECL
MSVCRT__wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
131 return MSVCRT__wcsicoll_l(str1
, str2
, NULL
);
134 /*********************************************************************
135 * _wcsnicoll_l (MSVCRT.@)
137 int CDECL
MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
138 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
140 MSVCRT_pthreadlocinfo locinfo
;
143 locinfo
= get_locinfo();
145 locinfo
= locale
->locinfo
;
147 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
148 return strncmpiW(str1
, str2
, count
);
149 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
150 str1
, count
, str2
, count
)-CSTR_EQUAL
;
153 /*********************************************************************
154 * _wcsnicoll (MSVCRT.@)
156 INT CDECL
MSVCRT__wcsnicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
158 return MSVCRT__wcsnicoll_l(str1
, str2
, count
, NULL
);
161 /*********************************************************************
162 * _wcsnset (MSVCRT.@)
164 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
166 MSVCRT_wchar_t
* ret
= str
;
167 while ((n
-- > 0) && *str
) *str
++ = c
;
171 /*********************************************************************
174 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsrev( MSVCRT_wchar_t
* str
)
176 MSVCRT_wchar_t
* ret
= str
;
177 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
180 MSVCRT_wchar_t t
= *end
;
187 /*********************************************************************
188 * _wcsset_s (MSVCRT.@)
190 int CDECL
MSVCRT__wcsset_s( MSVCRT_wchar_t
*str
, MSVCRT_size_t n
, MSVCRT_wchar_t c
)
192 MSVCRT_wchar_t
*p
= str
;
194 if(!MSVCRT_CHECK_PMT(str
!= NULL
)) return MSVCRT_EINVAL
;
195 if(!MSVCRT_CHECK_PMT(n
)) return MSVCRT_EINVAL
;
197 while(*p
&& --n
) *p
++ = c
;
200 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
201 *MSVCRT__errno() = MSVCRT_EINVAL
;
202 return MSVCRT_EINVAL
;
207 /*********************************************************************
210 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
212 MSVCRT_wchar_t
* ret
= str
;
213 while (*str
) *str
++ = c
;
217 /******************************************************************
218 * _wcsupr_s_l (MSVCRT.@)
220 int CDECL
MSVCRT__wcsupr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
,
221 MSVCRT__locale_t locale
)
223 MSVCRT_wchar_t
* ptr
= str
;
227 if (str
) *str
= '\0';
228 *MSVCRT__errno() = MSVCRT_EINVAL
;
229 return MSVCRT_EINVAL
;
235 /* FIXME: add locale support */
236 *ptr
= toupperW(*ptr
);
240 /* MSDN claims that the function should return and set errno to
241 * ERANGE, which doesn't seem to be true based on the tests. */
243 *MSVCRT__errno() = MSVCRT_EINVAL
;
244 return MSVCRT_EINVAL
;
247 /******************************************************************
248 * _wcsupr_s (MSVCRT.@)
251 INT CDECL
MSVCRT__wcsupr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
253 return MSVCRT__wcsupr_s_l( str
, n
, NULL
);
256 /******************************************************************
257 * _wcsupr_l (MSVCRT.@)
259 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsupr_l( MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
261 MSVCRT__wcsupr_s_l( str
, -1, locale
);
265 /******************************************************************
266 * _wcslwr_s_l (MSVCRT.@)
268 int CDECL
MSVCRT__wcslwr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
, MSVCRT__locale_t locale
)
270 MSVCRT_wchar_t
* ptr
= str
;
274 if (str
) *str
= '\0';
275 *MSVCRT__errno() = MSVCRT_EINVAL
;
276 return MSVCRT_EINVAL
;
282 *ptr
= tolowerW(*ptr
);
286 /* MSDN claims that the function should return and set errno to
287 * ERANGE, which doesn't seem to be true based on the tests. */
289 *MSVCRT__errno() = MSVCRT_EINVAL
;
290 return MSVCRT_EINVAL
;
293 /******************************************************************
294 * _wcslwr_s (MSVCRT.@)
296 int CDECL
MSVCRT__wcslwr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
298 return MSVCRT__wcslwr_s_l(str
, n
, NULL
);
301 /******************************************************************
302 * _wcslwr_l (MSVCRT.@)
304 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr_l( MSVCRT_wchar_t
* str
, MSVCRT__locale_t locale
)
306 MSVCRT__wcslwr_s_l(str
, -1, locale
);
310 /******************************************************************
313 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr( MSVCRT_wchar_t
* str
)
315 MSVCRT__wcslwr_s_l(str
, -1, NULL
);
319 /*********************************************************************
320 * _wcsncoll_l (MSVCRT.@)
322 int CDECL
MSVCRT__wcsncoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
323 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
325 MSVCRT_pthreadlocinfo locinfo
;
328 locinfo
= get_locinfo();
330 locinfo
= locale
->locinfo
;
332 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
333 return strncmpW(str1
, str2
, count
);
334 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, count
, str2
, count
)-CSTR_EQUAL
;
337 /*********************************************************************
338 * _wcsncoll (MSVCRT.@)
340 int CDECL
MSVCRT__wcsncoll(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
342 return MSVCRT__wcsncoll_l(str1
, str2
, count
, NULL
);
345 /*********************************************************************
346 * _wcstod_l (MSVCRT.@)
348 double CDECL
MSVCRT__wcstod_l(const MSVCRT_wchar_t
* str
, MSVCRT_wchar_t
** end
,
349 MSVCRT__locale_t locale
)
351 MSVCRT_pthreadlocinfo locinfo
;
352 unsigned __int64 d
=0, hlp
;
355 const MSVCRT_wchar_t
*p
;
357 long double lret
=1, expcnt
= 10;
358 BOOL found_digit
= FALSE
, negexp
;
360 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
363 locinfo
= get_locinfo();
365 locinfo
= locale
->locinfo
;
377 while(*p
>='0' && *p
<='9') {
379 hlp
= d
*10+*(p
++)-'0';
380 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
386 while(*p
>='0' && *p
<='9') {
390 if(*p
== *locinfo
->lconv
->decimal_point
)
393 while(*p
>='0' && *p
<='9') {
395 hlp
= d
*10+*(p
++)-'0';
396 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
402 while(*p
>='0' && *p
<='9')
407 *end
= (MSVCRT_wchar_t
*)str
;
411 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
421 if(*p
>='0' && *p
<='9') {
422 while(*p
>='0' && *p
<='9') {
423 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
429 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
430 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
433 if(*p
=='-' || *p
=='+')
439 fpcontrol
= _control87(0, 0);
440 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
441 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
450 expcnt
= expcnt
*expcnt
;
452 ret
= (long double)sign
* (negexp
? d
/lret
: d
*lret
);
454 _control87(fpcontrol
, 0xffffffff);
456 if((d
&& ret
==0.0) || isinf(ret
))
457 *MSVCRT__errno() = MSVCRT_ERANGE
;
460 *end
= (MSVCRT_wchar_t
*)p
;
465 /*********************************************************************
466 * wcsrtombs_l (INTERNAL)
468 static MSVCRT_size_t
MSVCRT_wcsrtombs_l(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
469 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
471 MSVCRT_pthreadlocinfo locinfo
;
472 MSVCRT_size_t tmp
= 0;
476 locinfo
= get_locinfo();
478 locinfo
= locale
->locinfo
;
481 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
482 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
483 if(!tmp
|| used_default
) {
484 *MSVCRT__errno() = MSVCRT_EILSEQ
;
492 MSVCRT_size_t i
, size
;
494 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
495 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
496 if(!size
|| used_default
) {
497 *MSVCRT__errno() = MSVCRT_EILSEQ
;
503 for(i
=0; i
<size
; i
++)
504 mbstr
[tmp
++] = buf
[i
];
515 /*********************************************************************
516 * _wcstombs_l (MSVCRT.@)
518 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
519 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
521 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
524 /*********************************************************************
525 * wcstombs (MSVCRT.@)
527 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
530 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
533 /*********************************************************************
534 * wcsrtombs (MSVCRT.@)
536 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
537 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
542 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
545 /*********************************************************************
546 * MSVCRT_wcsrtombs_s_l (INTERNAL)
548 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
549 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
550 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
554 if(!mbstr
&& !size
&& wcstr
) {
555 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
557 return *MSVCRT__errno();
563 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
564 if (size
) mbstr
[0] = '\0';
565 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
566 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
568 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
573 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
577 return *MSVCRT__errno();
578 }else if(conv
< size
)
579 mbstr
[conv
++] = '\0';
580 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
581 mbstr
[conv
-1] = '\0';
583 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
586 return MSVCRT_ERANGE
;
594 /*********************************************************************
595 * _wcstombs_s_l (MSVCRT.@)
597 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
598 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
599 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
601 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
604 /*********************************************************************
605 * wcstombs_s (MSVCRT.@)
607 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
608 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
610 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
613 /*********************************************************************
614 * wcsrtombs_s (MSVCRT.@)
616 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
617 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
622 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
625 /*********************************************************************
628 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
630 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
633 /*********************************************************************
636 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
638 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
641 /*********************************************************************
644 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
646 return MSVCRT__wcstod_l(str
, NULL
, locale
);
649 /*********************************************************************
650 * _wcstof_l (MSVCR120.@)
652 float CDECL
MSVCRT__wcstof_l( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
, MSVCRT__locale_t locale
)
654 return MSVCRT__wcstod_l(str
, end
, locale
);
657 /*********************************************************************
658 * wcstof (MSVCR120.@)
660 float CDECL
MSVCRT_wcstof( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
)
662 return MSVCRT__wcstof_l(str
, end
, NULL
);
665 /*********************************************************************
666 * arg_clbk_valist (INTERNAL)
668 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
673 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
674 else if(type
== VT_INT
)
675 ret
.get_int
= va_arg(*valist
, int);
676 else if(type
== VT_R8
)
677 ret
.get_double
= va_arg(*valist
, double);
678 else if(type
== VT_PTR
)
679 ret
.get_ptr
= va_arg(*valist
, void*);
681 ERR("Incorrect type\n");
688 /*********************************************************************
689 * arg_clbk_positional (INTERNAL)
691 static printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
693 printf_arg
*args
= ctx
;
697 /*********************************************************************
698 * _vsnprintf (MSVCRT.@)
700 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
701 const char *format
, __ms_va_list valist
)
703 static const char nullbyte
= '\0';
704 struct _str_ctx_a ctx
= {len
, str
};
707 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, 0,
708 arg_clbk_valist
, NULL
, &valist
);
709 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
713 static int puts_clbk_str_c99_a(void *ctx
, int len
, const char *str
)
715 struct _str_ctx_a
*out
= ctx
;
721 memcpy(out
->buf
, str
, out
->len
);
722 out
->buf
+= out
->len
;
727 memcpy(out
->buf
, str
, len
);
733 /*********************************************************************
734 * __stdio_common_vsprintf (MSVCRT.@)
736 int CDECL
MSVCRT__stdio_common_vsprintf( unsigned __int64 options
, char *str
, MSVCRT_size_t len
, const char *format
,
737 MSVCRT__locale_t locale
, __ms_va_list valist
)
739 static const char nullbyte
= '\0';
740 struct _str_ctx_a ctx
= {len
, str
};
743 if (options
& ~UCRTBASE_PRINTF_MASK
)
744 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
745 ret
= pf_printf_a(puts_clbk_str_c99_a
,
746 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
747 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
749 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
750 return ret
>len
? -1 : ret
;
752 if(len
) str
[len
-1] = 0;
753 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
758 /*********************************************************************
759 * _vsnprintf_l (MSVCRT.@)
761 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
762 MSVCRT__locale_t locale
, __ms_va_list valist
)
764 static const char nullbyte
= '\0';
765 struct _str_ctx_a ctx
= {len
, str
};
768 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, 0,
769 arg_clbk_valist
, NULL
, &valist
);
770 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
774 /*********************************************************************
775 * _vsprintf_l (MSVCRT.@)
777 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
778 MSVCRT__locale_t locale
, __ms_va_list valist
)
780 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
783 /*********************************************************************
784 * _sprintf_l (MSVCRT.@)
786 int CDECL
MSVCRT_sprintf_l(char *str
, const char *format
,
787 MSVCRT__locale_t locale
, ...)
791 __ms_va_start(valist
, locale
);
792 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
797 static int CDECL
MSVCRT_vsnprintf_s_l_opt( char *str
, MSVCRT_size_t sizeOfBuffer
,
798 MSVCRT_size_t count
, const char *format
, DWORD options
,
799 MSVCRT__locale_t locale
, __ms_va_list valist
)
801 static const char nullbyte
= '\0';
802 struct _str_ctx_a ctx
;
805 if(sizeOfBuffer
<count
+1 || count
==-1)
812 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
813 arg_clbk_valist
, NULL
, &valist
);
814 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
816 if(ret
<0 || ret
==len
) {
817 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
818 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
819 memset(str
, 0, sizeOfBuffer
);
829 /*********************************************************************
830 * _vsnprintf_s_l (MSVCRT.@)
832 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
833 MSVCRT_size_t count
, const char *format
,
834 MSVCRT__locale_t locale
, __ms_va_list valist
)
836 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
839 /*********************************************************************
840 * _vsprintf_s_l (MSVCRT.@)
842 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
843 MSVCRT__locale_t locale
, __ms_va_list valist
)
845 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
848 /*********************************************************************
849 * _sprintf_s_l (MSVCRT.@)
851 int CDECL
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
852 MSVCRT__locale_t locale
, ...)
856 __ms_va_start(valist
, locale
);
857 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
862 /*********************************************************************
863 * _vsnprintf_s (MSVCRT.@)
865 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
866 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
868 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
871 /*********************************************************************
872 * __stdio_common_vsnprintf_s (MSVCRT.@)
874 int CDECL
MSVCRT__stdio_common_vsnprintf_s( unsigned __int64 options
,
875 char *str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
876 const char *format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
878 if (options
& ~UCRTBASE_PRINTF_MASK
)
879 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
880 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
883 /*********************************************************************
884 * __stdio_common_vsprintf_s (MSVCRT.@)
886 int CDECL
MSVCRT__stdio_common_vsprintf_s( unsigned __int64 options
,
887 char *str
, MSVCRT_size_t count
, const char *format
,
888 MSVCRT__locale_t locale
, __ms_va_list valist
)
890 if (options
& ~UCRTBASE_PRINTF_MASK
)
891 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
892 return MSVCRT_vsnprintf_s_l_opt(str
, INT_MAX
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
895 /*********************************************************************
896 * vsprintf (MSVCRT.@)
898 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
900 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
903 /*********************************************************************
904 * vsprintf_s (MSVCRT.@)
906 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
908 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
911 /*********************************************************************
912 * _vscprintf (MSVCRT.@)
914 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
916 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
919 /*********************************************************************
920 * _vscprintf_p_l (MSVCRT.@)
922 int CDECL
MSVCRT__vscprintf_p_l(const char *format
,
923 MSVCRT__locale_t locale
, __ms_va_list args
)
925 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
926 struct _str_ctx_a puts_ctx
= {INT_MAX
, NULL
};
929 memset(args_ctx
, 0, sizeof(args_ctx
));
931 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
933 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
934 *MSVCRT__errno() = MSVCRT_EINVAL
;
936 } else if(ret
== 0) {
937 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
938 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
939 arg_clbk_valist
, NULL
, &args
);
941 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
942 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
943 arg_clbk_positional
, args_ctx
, NULL
);
949 /*********************************************************************
950 * _vscprintf_p (MSVCR80.@)
952 int CDECL
MSVCRT__vscprintf_p(const char *format
, __ms_va_list argptr
)
954 return MSVCRT__vscprintf_p_l(format
, NULL
, argptr
);
957 /*********************************************************************
958 * _snprintf (MSVCRT.@)
960 int CDECL
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
964 __ms_va_start(valist
, format
);
965 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
970 /*********************************************************************
971 * _snprintf_l (MSVCRT.@)
973 int CDECL
MSVCRT__snprintf_l(char *str
, unsigned int count
, MSVCRT__locale_t locale
,
974 const char *format
, ...)
978 __ms_va_start(valist
, format
);
979 retval
= MSVCRT_vsnprintf_l(str
, count
, format
, locale
, valist
);
984 /*********************************************************************
985 * _snprintf_s (MSVCRT.@)
987 int CDECL
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
988 const char *format
, ...)
992 __ms_va_start(valist
, format
);
993 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
998 /*********************************************************************
999 * _scprintf (MSVCRT.@)
1001 int CDECL
MSVCRT__scprintf(const char *format
, ...)
1004 __ms_va_list valist
;
1005 __ms_va_start(valist
, format
);
1006 retval
= MSVCRT__vscprintf(format
, valist
);
1007 __ms_va_end(valist
);
1011 /*********************************************************************
1012 * _vsnwprintf (MSVCRT.@)
1014 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1015 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1017 static const MSVCRT_wchar_t nullbyte
= '\0';
1018 struct _str_ctx_w ctx
= {len
, str
};
1021 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, 0,
1022 arg_clbk_valist
, NULL
, &valist
);
1023 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1027 /*********************************************************************
1028 * _vsnwprintf_l (MSVCRT.@)
1030 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1031 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
1032 __ms_va_list valist
)
1034 static const MSVCRT_wchar_t nullbyte
= '\0';
1035 struct _str_ctx_w ctx
= {len
, str
};
1038 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, 0,
1039 arg_clbk_valist
, NULL
, &valist
);
1040 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1044 /*********************************************************************
1045 * _vswprintf_p_l (MSVCRT.@)
1047 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1048 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1050 static const MSVCRT_wchar_t nullbyte
= '\0';
1051 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1052 struct _str_ctx_w puts_ctx
= {length
, buffer
};
1055 memset(args_ctx
, 0, sizeof(args_ctx
));
1057 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
1059 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1060 *MSVCRT__errno() = MSVCRT_EINVAL
;
1063 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1064 arg_clbk_valist
, NULL
, &args
);
1066 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
,
1067 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1068 arg_clbk_positional
, args_ctx
, NULL
);
1070 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
1074 /*********************************************************************
1075 * _vswprintf_p (MSVCR100.@)
1077 int CDECL
MSVCRT__vswprintf_p(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1078 const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1080 return MSVCRT_vswprintf_p_l(buffer
, length
, format
, NULL
, args
);
1083 /*********************************************************************
1084 * _vsnwprintf_s_l (MSVCRT.@)
1086 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1087 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1088 MSVCRT__locale_t locale
, __ms_va_list valist
)
1090 static const MSVCRT_wchar_t nullbyte
= '\0';
1091 struct _str_ctx_w ctx
;
1095 if(count
!=-1 && len
>count
+1)
1100 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1101 arg_clbk_valist
, NULL
, &valist
);
1102 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1104 if(ret
<0 || ret
==len
) {
1105 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
1106 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
1107 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
1117 /*********************************************************************
1118 * _vsnwprintf_s (MSVCRT.@)
1120 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1121 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1123 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
1124 format
, NULL
, valist
);
1127 /*********************************************************************
1128 * _snwprintf (MSVCRT.@)
1130 int CDECL
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
1133 __ms_va_list valist
;
1134 __ms_va_start(valist
, format
);
1135 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
1136 __ms_va_end(valist
);
1140 /*********************************************************************
1141 * _snwprintf_l (MSVCRT.@)
1143 int CDECL
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
1144 MSVCRT__locale_t locale
, ...)
1147 __ms_va_list valist
;
1148 __ms_va_start(valist
, locale
);
1149 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
1150 __ms_va_end(valist
);
1154 /*********************************************************************
1155 * _snwprintf_s (MSVCRT.@)
1157 int CDECL
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1158 const MSVCRT_wchar_t
*format
, ...)
1161 __ms_va_list valist
;
1162 __ms_va_start(valist
, format
);
1163 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1164 __ms_va_end(valist
);
1168 /*********************************************************************
1169 * _snwprintf_s_l (MSVCRT.@)
1171 int CDECL
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1172 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1175 __ms_va_list valist
;
1176 __ms_va_start(valist
, locale
);
1177 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
1178 __ms_va_end(valist
);
1182 static int puts_clbk_str_c99_w(void *ctx
, int len
, const MSVCRT_wchar_t
*str
)
1184 struct _str_ctx_w
*out
= ctx
;
1189 if(out
->len
< len
) {
1190 memcpy(out
->buf
, str
, out
->len
*sizeof(MSVCRT_wchar_t
));
1191 out
->buf
+= out
->len
;
1196 memcpy(out
->buf
, str
, len
*sizeof(MSVCRT_wchar_t
));
1202 /*********************************************************************
1203 * __stdio_common_vswprintf (MSVCRT.@)
1205 int CDECL
MSVCRT__stdio_common_vswprintf( unsigned __int64 options
,
1206 MSVCRT_wchar_t
*str
, MSVCRT_size_t len
, const MSVCRT_wchar_t
*format
,
1207 MSVCRT__locale_t locale
, __ms_va_list valist
)
1209 static const MSVCRT_wchar_t nullbyte
= '\0';
1210 struct _str_ctx_w ctx
= {len
, str
};
1213 if (options
& ~UCRTBASE_PRINTF_MASK
)
1214 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1215 ret
= pf_printf_w(puts_clbk_str_c99_w
,
1216 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
1217 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1219 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
1220 return ret
>len
? -1 : ret
;
1222 if(len
) str
[len
-1] = 0;
1223 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
1228 /*********************************************************************
1229 * sprintf (MSVCRT.@)
1231 int CDECL
MSVCRT_sprintf( char *str
, const char *format
, ... )
1236 __ms_va_start( ap
, format
);
1237 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
1242 /*********************************************************************
1243 * sprintf_s (MSVCRT.@)
1245 int CDECL
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
1250 __ms_va_start( ap
, format
);
1251 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
1256 /*********************************************************************
1257 * _scwprintf (MSVCRT.@)
1259 int CDECL
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
1264 __ms_va_start( ap
, format
);
1265 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1270 /*********************************************************************
1271 * swprintf (MSVCRT.@)
1273 int CDECL
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1278 __ms_va_start( ap
, format
);
1279 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1284 /*********************************************************************
1285 * swprintf_s (MSVCRT.@)
1287 int CDECL
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1288 const MSVCRT_wchar_t
*format
, ... )
1293 __ms_va_start(ap
, format
);
1294 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1300 /*********************************************************************
1301 * _swprintf_s_l (MSVCRT.@)
1303 int CDECL
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1304 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1309 __ms_va_start(ap
, locale
);
1310 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1316 /*********************************************************************
1317 * _vswprintf (MSVCRT.@)
1319 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1321 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1324 /*********************************************************************
1325 * _vswprintf (MSVCRT.@)
1327 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1328 MSVCRT__locale_t locale
, __ms_va_list args
)
1330 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1333 /*********************************************************************
1334 * _vscwprintf (MSVCRT.@)
1336 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1338 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1341 /*********************************************************************
1342 * _vscwprintf_l (MSVCRT.@)
1344 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1346 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1349 /*********************************************************************
1350 * _vscwprintf_p_l (MSVCRT.@)
1352 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1354 return MSVCRT_vswprintf_p_l( NULL
, INT_MAX
, format
, locale
, args
);
1357 /*********************************************************************
1358 * _vscwprintf_p (MSVCR100.@)
1360 int CDECL
MSVCRT__vscwprintf_p(const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1362 return MSVCRT_vswprintf_p_l(NULL
, INT_MAX
, format
, NULL
, args
);
1365 /*********************************************************************
1366 * vswprintf_s (MSVCRT.@)
1368 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1369 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1371 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1374 /*********************************************************************
1375 * _vswprintf_s_l (MSVCRT.@)
1377 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1378 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1380 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1381 format
, locale
, args
);
1384 /*********************************************************************
1385 * _vsprintf_p_l (MSVCRT.@)
1387 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1388 MSVCRT__locale_t locale
, __ms_va_list args
)
1390 static const char nullbyte
= '\0';
1391 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1392 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1395 memset(args_ctx
, 0, sizeof(args_ctx
));
1397 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1399 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1400 *MSVCRT__errno() = MSVCRT_EINVAL
;
1403 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1404 arg_clbk_valist
, NULL
, &args
);
1406 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1407 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1408 arg_clbk_positional
, args_ctx
, NULL
);
1410 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1414 /*********************************************************************
1415 * _vsprintf_p (MSVCRT.@)
1417 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1418 const char *format
, __ms_va_list args
)
1420 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1423 /*********************************************************************
1424 * _sprintf_p_l (MSVCRT.@)
1426 int CDECL
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1427 const char *format
, MSVCRT__locale_t locale
, ...)
1429 __ms_va_list valist
;
1432 __ms_va_start(valist
, locale
);
1433 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1434 __ms_va_end(valist
);
1439 /*********************************************************************
1440 * __swprintf_l (MSVCRT.@)
1442 int CDECL
MSVCRT___swprintf_l( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
1443 MSVCRT__locale_t locale
, ...)
1446 __ms_va_list valist
;
1447 __ms_va_start(valist
, locale
);
1448 retval
= MSVCRT_vswprintf_l(str
, format
, locale
, valist
);
1449 __ms_va_end(valist
);
1453 /*********************************************************************
1454 * _sprintf_p (MSVCR100.@)
1456 int CDECL
MSVCRT__sprintf_p(char *buffer
, MSVCRT_size_t length
, const char *format
, ...)
1458 __ms_va_list valist
;
1461 __ms_va_start(valist
, format
);
1462 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, valist
);
1463 __ms_va_end(valist
);
1468 /*********************************************************************
1469 * _swprintf_p_l (MSVCRT.@)
1471 int CDECL
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1472 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1474 __ms_va_list valist
;
1477 __ms_va_start(valist
, locale
);
1478 r
= MSVCRT_vswprintf_p_l(buffer
, length
, format
, locale
, valist
);
1479 __ms_va_end(valist
);
1484 /*********************************************************************
1485 * _wcscoll_l (MSVCRT.@)
1487 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1489 MSVCRT_pthreadlocinfo locinfo
;
1492 locinfo
= get_locinfo();
1494 locinfo
= locale
->locinfo
;
1496 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1497 return strcmpW(str1
, str2
);
1498 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1501 /*********************************************************************
1502 * wcscoll (MSVCRT.@)
1504 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1506 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1509 /*********************************************************************
1510 * wcspbrk (MSVCRT.@)
1512 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1514 const MSVCRT_wchar_t
* p
;
1518 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1524 /*********************************************************************
1525 * wcstok_s (MSVCRT.@)
1527 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1528 MSVCRT_wchar_t
**next_token
)
1530 MSVCRT_wchar_t
*ret
;
1532 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1533 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1534 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1536 if (!str
) str
= *next_token
;
1538 while (*str
&& strchrW( delim
, *str
)) str
++;
1539 if (!*str
) return NULL
;
1541 while (*str
&& !strchrW( delim
, *str
)) str
++;
1542 if (*str
) *str
++ = 0;
1547 /*********************************************************************
1550 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1552 return MSVCRT_wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1555 /*********************************************************************
1556 * _wctomb_s_l (MSVCRT.@)
1558 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1559 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1561 MSVCRT_pthreadlocinfo locinfo
;
1565 if(!mbchar
&& size
>0) {
1574 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1575 return MSVCRT_EINVAL
;
1578 locinfo
= get_locinfo();
1580 locinfo
= locale
->locinfo
;
1582 if(!locinfo
->lc_codepage
) {
1584 if(mbchar
&& size
>0)
1585 memset(mbchar
, 0, size
);
1586 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1587 return MSVCRT_EILSEQ
;
1590 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1591 return MSVCRT_ERANGE
;
1599 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1600 if(!mblen
|| error
) {
1601 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1602 if(mbchar
&& size
>0)
1603 memset(mbchar
, 0, size
);
1605 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1606 return MSVCRT_ERANGE
;
1609 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1610 return MSVCRT_EILSEQ
;
1618 /*********************************************************************
1619 * wctomb_s (MSVCRT.@)
1621 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1623 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1626 /*********************************************************************
1627 * _wctomb_l (MSVCRT.@)
1629 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1633 MSVCRT__wctomb_s_l(&len
, dst
, dst
? MSVCRT_MB_LEN_MAX
: 0, ch
, locale
);
1637 /*********************************************************************
1640 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1642 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1645 /*********************************************************************
1648 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1652 UINT codepage
= get_locinfo()->lc_codepage
;
1656 return (signed char)wchar
;
1659 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1664 /*********************************************************************
1665 * wcrtomb (MSVCRT.@)
1667 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1671 return MSVCRT_wctomb(dst
, ch
);
1674 /*********************************************************************
1675 * iswalnum (MSVCRT.@)
1677 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1679 return isalnumW( wc
);
1682 /*********************************************************************
1683 * iswalpha (MSVCRT.@)
1685 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1687 return isalphaW( wc
);
1690 /*********************************************************************
1691 * iswalpha_l (MSVCRT.@)
1693 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1695 return isalphaW( wc
);
1698 /*********************************************************************
1699 * iswcntrl (MSVCRT.@)
1701 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1703 return iscntrlW( wc
);
1706 /*********************************************************************
1707 * iswdigit (MSVCRT.@)
1709 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1711 return isdigitW( wc
);
1714 /*********************************************************************
1715 * _iswdigit_l (MSVCRT.@)
1717 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1719 return isdigitW( wc
);
1722 /*********************************************************************
1723 * iswgraph (MSVCRT.@)
1725 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1727 return isgraphW( wc
);
1730 /*********************************************************************
1731 * iswlower (MSVCRT.@)
1733 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1735 return islowerW( wc
);
1738 /*********************************************************************
1739 * iswprint (MSVCRT.@)
1741 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1743 return isprintW( wc
);
1746 /*********************************************************************
1747 * _iswpunct_l (MSVCRT.@)
1749 INT CDECL
MSVCRT__iswpunct_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1751 return ispunctW( wc
);
1754 /*********************************************************************
1755 * iswpunct (MSVCRT.@)
1757 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1759 return ispunctW( wc
);
1762 /*********************************************************************
1763 * _iswspace_l (MSVCRT.@)
1765 INT CDECL
MSVCRT__iswspace_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1767 return isspaceW( wc
);
1770 /*********************************************************************
1771 * iswspace (MSVCRT.@)
1773 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1775 return isspaceW( wc
);
1778 /*********************************************************************
1779 * iswupper (MSVCRT.@)
1781 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1783 return isupperW( wc
);
1786 /*********************************************************************
1787 * iswxdigit (MSVCRT.@)
1789 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1791 return isxdigitW( wc
);
1794 /*********************************************************************
1795 * wcscpy_s (MSVCRT.@)
1797 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1799 MSVCRT_size_t size
= 0;
1801 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1802 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1806 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1808 size
= strlenW(wcSrc
) + 1;
1810 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1811 return MSVCRT_ERANGE
;
1813 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1818 /******************************************************************
1819 * wcsncpy (MSVCRT.@)
1821 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1822 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1827 if(!(s1
[i
] = s2
[i
])) break;
1833 /******************************************************************
1834 * wcsncpy_s (MSVCRT.@)
1836 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1837 MSVCRT_size_t count
)
1840 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1842 if(!wcDest
&& !numElement
&& !count
)
1845 if (!wcDest
|| !numElement
)
1846 return MSVCRT_EINVAL
;
1851 return count
? MSVCRT_EINVAL
: 0;
1854 while (numElement
&& count
&& *wcSrc
)
1860 if (!numElement
&& truncate
)
1863 return MSVCRT_STRUNCATE
;
1865 else if (!numElement
)
1868 return MSVCRT_ERANGE
;
1875 /******************************************************************
1876 * wcscat_s (MSVCRT.@)
1879 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
1881 MSVCRT_wchar_t
* ptr
= dst
;
1883 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
1887 return MSVCRT_EINVAL
;
1890 /* seek to end of dst string (or elem if no end of string is found */
1891 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
1892 while (ptr
< dst
+ elem
)
1894 if ((*ptr
++ = *src
++) == '\0') return 0;
1896 /* not enough space */
1898 return MSVCRT_ERANGE
;
1901 /*********************************************************************
1902 * wcsncat_s (MSVCRT.@)
1905 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
1906 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
1908 MSVCRT_size_t srclen
;
1909 MSVCRT_wchar_t dststart
;
1912 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1913 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
1914 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
1919 for (dststart
= 0; dststart
< elem
; dststart
++)
1921 if (dst
[dststart
] == '\0')
1924 if (dststart
== elem
)
1926 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
1927 return MSVCRT_EINVAL
;
1930 if (count
== MSVCRT__TRUNCATE
)
1932 srclen
= strlenW(src
);
1933 if (srclen
>= (elem
- dststart
))
1935 srclen
= elem
- dststart
- 1;
1936 ret
= MSVCRT_STRUNCATE
;
1940 srclen
= min(strlenW(src
), count
);
1941 if (srclen
< (elem
- dststart
))
1943 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
1944 dst
[dststart
+srclen
] = '\0';
1947 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
1949 return MSVCRT_ERANGE
;
1952 /*********************************************************************
1953 * _wcstoi64_l (MSVCRT.@)
1955 * FIXME: locale parameter is ignored
1957 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
1958 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1960 BOOL negative
= FALSE
;
1963 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1965 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1966 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1967 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1969 while(isspaceW(*nptr
)) nptr
++;
1974 } else if(*nptr
== '+')
1977 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1990 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1993 if(cur
>='0' && cur
<='9') {
1998 if(cur
<'a' || cur
>='a'+base
-10)
2008 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
2009 ret
= MSVCRT_I64_MAX
;
2010 *MSVCRT__errno() = MSVCRT_ERANGE
;
2011 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
2012 ret
= MSVCRT_I64_MIN
;
2013 *MSVCRT__errno() = MSVCRT_ERANGE
;
2019 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2024 /*********************************************************************
2025 * _wcstoi64 (MSVCRT.@)
2027 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
2028 MSVCRT_wchar_t
**endptr
, int base
)
2030 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
2033 /*********************************************************************
2034 * _wcstol_l (MSVCRT.@)
2036 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
2037 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2039 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
2041 if(ret
> MSVCRT_LONG_MAX
) {
2042 ret
= MSVCRT_LONG_MAX
;
2043 *MSVCRT__errno() = MSVCRT_ERANGE
;
2044 }else if(ret
< MSVCRT_LONG_MIN
) {
2045 ret
= MSVCRT_LONG_MIN
;
2046 *MSVCRT__errno() = MSVCRT_ERANGE
;
2051 /*********************************************************************
2052 * _wtoi_l (MSVCRT.@)
2054 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2056 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2060 *MSVCRT__errno() = MSVCRT_ERANGE
;
2061 } else if(ret
< INT_MIN
) {
2063 *MSVCRT__errno() = MSVCRT_ERANGE
;
2068 /*********************************************************************
2071 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
2073 return MSVCRT__wtoi_l(str
, NULL
);
2076 /*********************************************************************
2077 * _wtol_l (MSVCRT.@)
2079 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2081 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2083 if(ret
> MSVCRT_LONG_MAX
) {
2084 ret
= MSVCRT_LONG_MAX
;
2085 *MSVCRT__errno() = MSVCRT_ERANGE
;
2086 } else if(ret
< MSVCRT_LONG_MIN
) {
2087 ret
= MSVCRT_LONG_MIN
;
2088 *MSVCRT__errno() = MSVCRT_ERANGE
;
2093 /*********************************************************************
2096 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
2098 return MSVCRT__wtol_l(str
, NULL
);
2101 /*********************************************************************
2102 * _wtoll_l (MSVCR120.@)
2104 MSVCRT_longlong __cdecl
MSVCRT__wtoll_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2106 return MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2109 /*********************************************************************
2110 * _wtoll (MSVCR120.@)
2112 MSVCRT_longlong __cdecl
MSVCRT__wtoll(const MSVCRT_wchar_t
*str
)
2114 return MSVCRT__wtoll_l(str
, NULL
);
2117 /*********************************************************************
2118 * _wcstoui64_l (MSVCRT.@)
2120 * FIXME: locale parameter is ignored
2122 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
2123 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2125 BOOL negative
= FALSE
;
2126 unsigned __int64 ret
= 0;
2128 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2130 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2131 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2132 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2134 while(isspaceW(*nptr
)) nptr
++;
2139 } else if(*nptr
== '+')
2142 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
2155 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
2158 if(cur
>='0' && cur
<='9') {
2163 if(cur
<'a' || cur
>='a'+base
-10)
2170 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
2171 ret
= MSVCRT_UI64_MAX
;
2172 *MSVCRT__errno() = MSVCRT_ERANGE
;
2178 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2180 return negative
? -ret
: ret
;
2183 /*********************************************************************
2184 * _wcstoui64 (MSVCRT.@)
2186 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
2187 MSVCRT_wchar_t
**endptr
, int base
)
2189 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
2192 /*********************************************************************
2193 * _wcstoul_l (MSVCRT.@)
2195 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
2196 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2198 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
2200 if(ret
> MSVCRT_ULONG_MAX
) {
2201 ret
= MSVCRT_ULONG_MAX
;
2202 *MSVCRT__errno() = MSVCRT_ERANGE
;
2207 /*********************************************************************
2208 * wcstoul (MSVCRT.@)
2210 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
2212 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
2215 /******************************************************************
2216 * wcsnlen (MSVCRT.@)
2218 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
2222 for (i
= 0; i
< maxlen
; i
++)
2227 /*********************************************************************
2228 * _towupper_l (MSVCRT.@)
2230 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2235 /*********************************************************************
2236 * towupper (MSVCRT.@)
2238 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
2240 return MSVCRT__towupper_l(c
, NULL
);
2243 /*********************************************************************
2244 * _towlower_l (MSVCRT.@)
2246 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2251 /*********************************************************************
2252 * towlower (MSVCRT.@)
2254 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
2256 return MSVCRT__towlower_l(c
, NULL
);
2259 /*********************************************************************
2262 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
2264 return strchrW(str
, ch
);
2267 /***********************************************************************
2270 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
2272 return strlenW(str
);
2275 /*********************************************************************
2278 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
2280 return strstrW(str
, sub
);
2283 /*********************************************************************
2284 * _wtoi64_l (MSVCRT.@)
2286 __int64 CDECL
MSVCRT__wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2288 ULONGLONG RunningTotal
= 0;
2289 BOOL bMinus
= FALSE
;
2291 while (isspaceW(*str
)) {
2297 } else if (*str
== '-') {
2302 while (*str
>= '0' && *str
<= '9') {
2303 RunningTotal
= RunningTotal
* 10 + *str
- '0';
2307 return bMinus
? -RunningTotal
: RunningTotal
;
2310 /*********************************************************************
2311 * _wtoi64 (MSVCRT.@)
2313 __int64 CDECL
MSVCRT__wtoi64(const MSVCRT_wchar_t
*str
)
2315 return MSVCRT__wtoi64_l(str
, NULL
);
2318 /*********************************************************************
2319 * wcsncmp (MSVCRT.@)
2321 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
2323 return strncmpW(str1
, str2
, n
);
2326 /*********************************************************************
2327 * _wcsxfrm_l (MSVCRT.@)
2329 MSVCRT_size_t CDECL
MSVCRT__wcsxfrm_l(MSVCRT_wchar_t
*dest
, const MSVCRT_wchar_t
*src
,
2330 MSVCRT_size_t len
, MSVCRT__locale_t locale
)
2332 MSVCRT_pthreadlocinfo locinfo
;
2335 if(!MSVCRT_CHECK_PMT(src
)) return INT_MAX
;
2336 if(!MSVCRT_CHECK_PMT(dest
|| !len
)) return INT_MAX
;
2339 FIXME("len > INT_MAX not supported\n");
2344 locinfo
= get_locinfo();
2346 locinfo
= locale
->locinfo
;
2348 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]) {
2349 MSVCRT_wcsncpy(dest
, src
, len
);
2350 return strlenW(src
);
2353 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2354 LCMAP_SORTKEY
, src
, -1, NULL
, 0);
2356 if(len
) dest
[0] = 0;
2357 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2360 if(!len
) return ret
-1;
2364 *MSVCRT__errno() = MSVCRT_ERANGE
;
2368 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2369 LCMAP_SORTKEY
, src
, -1, dest
, len
) - 1;
2370 for(i
=ret
; i
>=0; i
--)
2371 dest
[i
] = ((unsigned char*)dest
)[i
];
2375 /*********************************************************************
2376 * wcsxfrm (MSVCRT.@)
2378 MSVCRT_size_t CDECL
MSVCRT_wcsxfrm(MSVCRT_wchar_t
*dest
,
2379 const MSVCRT_wchar_t
*src
, MSVCRT_size_t len
)
2381 return MSVCRT__wcsxfrm_l(dest
, src
, len
, NULL
);