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
;
480 if(!locinfo
->lc_codepage
) {
484 return strlenW(*wcstr
);
486 for(i
=0; i
<count
; i
++) {
487 if((*wcstr
)[i
] > 255) {
488 *MSVCRT__errno() = MSVCRT_EILSEQ
;
492 mbstr
[i
] = (*wcstr
)[i
];
493 if(!(*wcstr
)[i
]) break;
499 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
500 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
501 if(!tmp
|| used_default
) {
502 *MSVCRT__errno() = MSVCRT_EILSEQ
;
510 MSVCRT_size_t i
, size
;
512 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
513 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
514 if(!size
|| used_default
) {
515 *MSVCRT__errno() = MSVCRT_EILSEQ
;
521 for(i
=0; i
<size
; i
++)
522 mbstr
[tmp
++] = buf
[i
];
533 /*********************************************************************
534 * _wcstombs_l (MSVCRT.@)
536 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
537 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
539 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
542 /*********************************************************************
543 * wcstombs (MSVCRT.@)
545 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
548 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
551 /*********************************************************************
552 * wcsrtombs (MSVCRT.@)
554 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
555 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
560 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
563 /*********************************************************************
564 * MSVCRT_wcsrtombs_s_l (INTERNAL)
566 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
567 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
568 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
572 if(!mbstr
&& !size
&& wcstr
) {
573 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
575 return *MSVCRT__errno();
581 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
582 if (size
) mbstr
[0] = '\0';
583 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
584 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
586 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
591 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
595 return *MSVCRT__errno();
596 }else if(conv
< size
)
597 mbstr
[conv
++] = '\0';
598 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
599 mbstr
[conv
-1] = '\0';
601 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
604 return MSVCRT_ERANGE
;
612 /*********************************************************************
613 * _wcstombs_s_l (MSVCRT.@)
615 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
616 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
617 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
619 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
622 /*********************************************************************
623 * wcstombs_s (MSVCRT.@)
625 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
626 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
628 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
631 /*********************************************************************
632 * wcsrtombs_s (MSVCRT.@)
634 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
635 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
640 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
643 /*********************************************************************
646 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
648 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
651 /*********************************************************************
654 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
656 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
659 /*********************************************************************
662 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
664 return MSVCRT__wcstod_l(str
, NULL
, locale
);
667 /*********************************************************************
668 * _wcstof_l (MSVCR120.@)
670 float CDECL
MSVCRT__wcstof_l( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
, MSVCRT__locale_t locale
)
672 return MSVCRT__wcstod_l(str
, end
, locale
);
675 /*********************************************************************
676 * wcstof (MSVCR120.@)
678 float CDECL
MSVCRT_wcstof( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
)
680 return MSVCRT__wcstof_l(str
, end
, NULL
);
683 /*********************************************************************
684 * arg_clbk_valist (INTERNAL)
686 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
691 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
692 else if(type
== VT_INT
)
693 ret
.get_int
= va_arg(*valist
, int);
694 else if(type
== VT_R8
)
695 ret
.get_double
= va_arg(*valist
, double);
696 else if(type
== VT_PTR
)
697 ret
.get_ptr
= va_arg(*valist
, void*);
699 ERR("Incorrect type\n");
706 /*********************************************************************
707 * arg_clbk_positional (INTERNAL)
709 static printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
711 printf_arg
*args
= ctx
;
715 /*********************************************************************
716 * _vsnprintf (MSVCRT.@)
718 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
719 const char *format
, __ms_va_list valist
)
721 static const char nullbyte
= '\0';
722 struct _str_ctx_a ctx
= {len
, str
};
725 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, 0,
726 arg_clbk_valist
, NULL
, &valist
);
727 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
731 static int puts_clbk_str_c99_a(void *ctx
, int len
, const char *str
)
733 struct _str_ctx_a
*out
= ctx
;
739 memcpy(out
->buf
, str
, out
->len
);
740 out
->buf
+= out
->len
;
745 memcpy(out
->buf
, str
, len
);
751 /*********************************************************************
752 * __stdio_common_vsprintf (MSVCRT.@)
754 int CDECL
MSVCRT__stdio_common_vsprintf( unsigned __int64 options
, char *str
, MSVCRT_size_t len
, const char *format
,
755 MSVCRT__locale_t locale
, __ms_va_list valist
)
757 static const char nullbyte
= '\0';
758 struct _str_ctx_a ctx
= {len
, str
};
761 if (options
& ~UCRTBASE_PRINTF_MASK
)
762 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
763 ret
= pf_printf_a(puts_clbk_str_c99_a
,
764 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
765 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
767 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
768 return ret
>len
? -1 : ret
;
770 if(len
) str
[len
-1] = 0;
771 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
776 /*********************************************************************
777 * _vsnprintf_l (MSVCRT.@)
779 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
780 MSVCRT__locale_t locale
, __ms_va_list valist
)
782 static const char nullbyte
= '\0';
783 struct _str_ctx_a ctx
= {len
, str
};
786 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, 0,
787 arg_clbk_valist
, NULL
, &valist
);
788 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
792 /*********************************************************************
793 * _vsprintf_l (MSVCRT.@)
795 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
796 MSVCRT__locale_t locale
, __ms_va_list valist
)
798 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
801 /*********************************************************************
802 * _sprintf_l (MSVCRT.@)
804 int CDECL
MSVCRT_sprintf_l(char *str
, const char *format
,
805 MSVCRT__locale_t locale
, ...)
809 __ms_va_start(valist
, locale
);
810 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
815 static int CDECL
MSVCRT_vsnprintf_s_l_opt( char *str
, MSVCRT_size_t sizeOfBuffer
,
816 MSVCRT_size_t count
, const char *format
, DWORD options
,
817 MSVCRT__locale_t locale
, __ms_va_list valist
)
819 static const char nullbyte
= '\0';
820 struct _str_ctx_a ctx
;
823 if(sizeOfBuffer
<count
+1 || count
==-1)
830 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
831 arg_clbk_valist
, NULL
, &valist
);
832 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
834 if(ret
<0 || ret
==len
) {
835 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
836 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
837 memset(str
, 0, sizeOfBuffer
);
847 /*********************************************************************
848 * _vsnprintf_s_l (MSVCRT.@)
850 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
851 MSVCRT_size_t count
, const char *format
,
852 MSVCRT__locale_t locale
, __ms_va_list valist
)
854 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
857 /*********************************************************************
858 * _vsprintf_s_l (MSVCRT.@)
860 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
861 MSVCRT__locale_t locale
, __ms_va_list valist
)
863 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
866 /*********************************************************************
867 * _sprintf_s_l (MSVCRT.@)
869 int CDECL
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
870 MSVCRT__locale_t locale
, ...)
874 __ms_va_start(valist
, locale
);
875 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
880 /*********************************************************************
881 * _vsnprintf_s (MSVCRT.@)
883 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
884 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
886 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
889 /*********************************************************************
890 * __stdio_common_vsnprintf_s (MSVCRT.@)
892 int CDECL
MSVCRT__stdio_common_vsnprintf_s( unsigned __int64 options
,
893 char *str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
894 const char *format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
896 if (options
& ~UCRTBASE_PRINTF_MASK
)
897 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
898 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
901 /*********************************************************************
902 * __stdio_common_vsprintf_s (MSVCRT.@)
904 int CDECL
MSVCRT__stdio_common_vsprintf_s( unsigned __int64 options
,
905 char *str
, MSVCRT_size_t count
, const char *format
,
906 MSVCRT__locale_t locale
, __ms_va_list valist
)
908 if (options
& ~UCRTBASE_PRINTF_MASK
)
909 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
910 return MSVCRT_vsnprintf_s_l_opt(str
, INT_MAX
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
913 /*********************************************************************
914 * vsprintf (MSVCRT.@)
916 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
918 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
921 /*********************************************************************
922 * vsprintf_s (MSVCRT.@)
924 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
926 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
929 /*********************************************************************
930 * _vscprintf (MSVCRT.@)
932 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
934 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
937 /*********************************************************************
938 * _vscprintf_p_l (MSVCRT.@)
940 int CDECL
MSVCRT__vscprintf_p_l(const char *format
,
941 MSVCRT__locale_t locale
, __ms_va_list args
)
943 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
944 struct _str_ctx_a puts_ctx
= {INT_MAX
, NULL
};
947 memset(args_ctx
, 0, sizeof(args_ctx
));
949 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
951 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
952 *MSVCRT__errno() = MSVCRT_EINVAL
;
954 } else if(ret
== 0) {
955 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
956 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
957 arg_clbk_valist
, NULL
, &args
);
959 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
960 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
961 arg_clbk_positional
, args_ctx
, NULL
);
967 /*********************************************************************
968 * _vscprintf_p (MSVCR80.@)
970 int CDECL
MSVCRT__vscprintf_p(const char *format
, __ms_va_list argptr
)
972 return MSVCRT__vscprintf_p_l(format
, NULL
, argptr
);
975 /*********************************************************************
976 * _snprintf (MSVCRT.@)
978 int CDECL
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
982 __ms_va_start(valist
, format
);
983 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
988 /*********************************************************************
989 * _snprintf_l (MSVCRT.@)
991 int CDECL
MSVCRT__snprintf_l(char *str
, unsigned int count
, MSVCRT__locale_t locale
,
992 const char *format
, ...)
996 __ms_va_start(valist
, format
);
997 retval
= MSVCRT_vsnprintf_l(str
, count
, format
, locale
, valist
);
1002 /*********************************************************************
1003 * _snprintf_s (MSVCRT.@)
1005 int CDECL
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
1006 const char *format
, ...)
1009 __ms_va_list valist
;
1010 __ms_va_start(valist
, format
);
1011 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1012 __ms_va_end(valist
);
1016 /*********************************************************************
1017 * _scprintf (MSVCRT.@)
1019 int CDECL
MSVCRT__scprintf(const char *format
, ...)
1022 __ms_va_list valist
;
1023 __ms_va_start(valist
, format
);
1024 retval
= MSVCRT__vscprintf(format
, valist
);
1025 __ms_va_end(valist
);
1029 /*********************************************************************
1030 * _vsnwprintf (MSVCRT.@)
1032 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1033 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1035 static const MSVCRT_wchar_t nullbyte
= '\0';
1036 struct _str_ctx_w ctx
= {len
, str
};
1039 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, 0,
1040 arg_clbk_valist
, NULL
, &valist
);
1041 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1045 /*********************************************************************
1046 * _vsnwprintf_l (MSVCRT.@)
1048 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1049 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
1050 __ms_va_list valist
)
1052 static const MSVCRT_wchar_t nullbyte
= '\0';
1053 struct _str_ctx_w ctx
= {len
, str
};
1056 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, 0,
1057 arg_clbk_valist
, NULL
, &valist
);
1058 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1062 /*********************************************************************
1063 * _vswprintf_p_l (MSVCRT.@)
1065 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1066 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1068 static const MSVCRT_wchar_t nullbyte
= '\0';
1069 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1070 struct _str_ctx_w puts_ctx
= {length
, buffer
};
1073 memset(args_ctx
, 0, sizeof(args_ctx
));
1075 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
1077 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1078 *MSVCRT__errno() = MSVCRT_EINVAL
;
1081 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1082 arg_clbk_valist
, NULL
, &args
);
1084 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
,
1085 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1086 arg_clbk_positional
, args_ctx
, NULL
);
1088 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
1092 /*********************************************************************
1093 * _vswprintf_p (MSVCR100.@)
1095 int CDECL
MSVCRT__vswprintf_p(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1096 const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1098 return MSVCRT_vswprintf_p_l(buffer
, length
, format
, NULL
, args
);
1101 /*********************************************************************
1102 * _vsnwprintf_s_l (MSVCRT.@)
1104 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1105 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1106 MSVCRT__locale_t locale
, __ms_va_list valist
)
1108 static const MSVCRT_wchar_t nullbyte
= '\0';
1109 struct _str_ctx_w ctx
;
1113 if(count
!=-1 && len
>count
+1)
1118 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1119 arg_clbk_valist
, NULL
, &valist
);
1120 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1122 if(ret
<0 || ret
==len
) {
1123 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
1124 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
1125 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
1135 /*********************************************************************
1136 * _vsnwprintf_s (MSVCRT.@)
1138 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1139 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1141 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
1142 format
, NULL
, valist
);
1145 /*********************************************************************
1146 * _snwprintf (MSVCRT.@)
1148 int CDECL
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
1151 __ms_va_list valist
;
1152 __ms_va_start(valist
, format
);
1153 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
1154 __ms_va_end(valist
);
1158 /*********************************************************************
1159 * _snwprintf_l (MSVCRT.@)
1161 int CDECL
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
1162 MSVCRT__locale_t locale
, ...)
1165 __ms_va_list valist
;
1166 __ms_va_start(valist
, locale
);
1167 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
1168 __ms_va_end(valist
);
1172 /*********************************************************************
1173 * _snwprintf_s (MSVCRT.@)
1175 int CDECL
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1176 const MSVCRT_wchar_t
*format
, ...)
1179 __ms_va_list valist
;
1180 __ms_va_start(valist
, format
);
1181 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1182 __ms_va_end(valist
);
1186 /*********************************************************************
1187 * _snwprintf_s_l (MSVCRT.@)
1189 int CDECL
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1190 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1193 __ms_va_list valist
;
1194 __ms_va_start(valist
, locale
);
1195 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
1196 __ms_va_end(valist
);
1200 static int puts_clbk_str_c99_w(void *ctx
, int len
, const MSVCRT_wchar_t
*str
)
1202 struct _str_ctx_w
*out
= ctx
;
1207 if(out
->len
< len
) {
1208 memcpy(out
->buf
, str
, out
->len
*sizeof(MSVCRT_wchar_t
));
1209 out
->buf
+= out
->len
;
1214 memcpy(out
->buf
, str
, len
*sizeof(MSVCRT_wchar_t
));
1220 /*********************************************************************
1221 * __stdio_common_vswprintf (MSVCRT.@)
1223 int CDECL
MSVCRT__stdio_common_vswprintf( unsigned __int64 options
,
1224 MSVCRT_wchar_t
*str
, MSVCRT_size_t len
, const MSVCRT_wchar_t
*format
,
1225 MSVCRT__locale_t locale
, __ms_va_list valist
)
1227 static const MSVCRT_wchar_t nullbyte
= '\0';
1228 struct _str_ctx_w ctx
= {len
, str
};
1231 if (options
& ~UCRTBASE_PRINTF_MASK
)
1232 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1233 ret
= pf_printf_w(puts_clbk_str_c99_w
,
1234 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
1235 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1237 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
1238 return ret
>len
? -1 : ret
;
1240 if(len
) str
[len
-1] = 0;
1241 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
1246 /*********************************************************************
1247 * sprintf (MSVCRT.@)
1249 int CDECL
MSVCRT_sprintf( char *str
, const char *format
, ... )
1254 __ms_va_start( ap
, format
);
1255 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
1260 /*********************************************************************
1261 * sprintf_s (MSVCRT.@)
1263 int CDECL
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
1268 __ms_va_start( ap
, format
);
1269 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
1274 /*********************************************************************
1275 * _scwprintf (MSVCRT.@)
1277 int CDECL
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
1282 __ms_va_start( ap
, format
);
1283 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1288 /*********************************************************************
1289 * swprintf (MSVCRT.@)
1291 int CDECL
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1296 __ms_va_start( ap
, format
);
1297 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1302 /*********************************************************************
1303 * swprintf_s (MSVCRT.@)
1305 int CDECL
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1306 const MSVCRT_wchar_t
*format
, ... )
1311 __ms_va_start(ap
, format
);
1312 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1318 /*********************************************************************
1319 * _swprintf_s_l (MSVCRT.@)
1321 int CDECL
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1322 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1327 __ms_va_start(ap
, locale
);
1328 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1334 /*********************************************************************
1335 * _vswprintf (MSVCRT.@)
1337 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1339 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1342 /*********************************************************************
1343 * _vswprintf (MSVCRT.@)
1345 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1346 MSVCRT__locale_t locale
, __ms_va_list args
)
1348 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1351 /*********************************************************************
1352 * _vscwprintf (MSVCRT.@)
1354 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1356 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1359 /*********************************************************************
1360 * _vscwprintf_l (MSVCRT.@)
1362 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1364 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1367 /*********************************************************************
1368 * _vscwprintf_p_l (MSVCRT.@)
1370 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1372 return MSVCRT_vswprintf_p_l( NULL
, INT_MAX
, format
, locale
, args
);
1375 /*********************************************************************
1376 * _vscwprintf_p (MSVCR100.@)
1378 int CDECL
MSVCRT__vscwprintf_p(const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1380 return MSVCRT_vswprintf_p_l(NULL
, INT_MAX
, format
, NULL
, args
);
1383 /*********************************************************************
1384 * vswprintf_s (MSVCRT.@)
1386 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1387 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1389 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1392 /*********************************************************************
1393 * _vswprintf_s_l (MSVCRT.@)
1395 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1396 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1398 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1399 format
, locale
, args
);
1402 /*********************************************************************
1403 * _vsprintf_p_l (MSVCRT.@)
1405 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1406 MSVCRT__locale_t locale
, __ms_va_list args
)
1408 static const char nullbyte
= '\0';
1409 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1410 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1413 memset(args_ctx
, 0, sizeof(args_ctx
));
1415 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1417 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1418 *MSVCRT__errno() = MSVCRT_EINVAL
;
1421 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1422 arg_clbk_valist
, NULL
, &args
);
1424 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1425 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1426 arg_clbk_positional
, args_ctx
, NULL
);
1428 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1432 /*********************************************************************
1433 * _vsprintf_p (MSVCRT.@)
1435 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1436 const char *format
, __ms_va_list args
)
1438 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1441 /*********************************************************************
1442 * _sprintf_p_l (MSVCRT.@)
1444 int CDECL
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1445 const char *format
, MSVCRT__locale_t locale
, ...)
1447 __ms_va_list valist
;
1450 __ms_va_start(valist
, locale
);
1451 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1452 __ms_va_end(valist
);
1457 /*********************************************************************
1458 * __swprintf_l (MSVCRT.@)
1460 int CDECL
MSVCRT___swprintf_l( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
1461 MSVCRT__locale_t locale
, ...)
1464 __ms_va_list valist
;
1465 __ms_va_start(valist
, locale
);
1466 retval
= MSVCRT_vswprintf_l(str
, format
, locale
, valist
);
1467 __ms_va_end(valist
);
1471 /*********************************************************************
1472 * _sprintf_p (MSVCR100.@)
1474 int CDECL
MSVCRT__sprintf_p(char *buffer
, MSVCRT_size_t length
, const char *format
, ...)
1476 __ms_va_list valist
;
1479 __ms_va_start(valist
, format
);
1480 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, valist
);
1481 __ms_va_end(valist
);
1486 /*********************************************************************
1487 * _swprintf_p_l (MSVCRT.@)
1489 int CDECL
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1490 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1492 __ms_va_list valist
;
1495 __ms_va_start(valist
, locale
);
1496 r
= MSVCRT_vswprintf_p_l(buffer
, length
, format
, locale
, valist
);
1497 __ms_va_end(valist
);
1502 /*********************************************************************
1503 * _wcscoll_l (MSVCRT.@)
1505 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1507 MSVCRT_pthreadlocinfo locinfo
;
1510 locinfo
= get_locinfo();
1512 locinfo
= locale
->locinfo
;
1514 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1515 return strcmpW(str1
, str2
);
1516 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1519 /*********************************************************************
1520 * wcscoll (MSVCRT.@)
1522 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1524 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1527 /*********************************************************************
1528 * wcspbrk (MSVCRT.@)
1530 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1532 const MSVCRT_wchar_t
* p
;
1536 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1542 /*********************************************************************
1543 * wcstok_s (MSVCRT.@)
1545 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1546 MSVCRT_wchar_t
**next_token
)
1548 MSVCRT_wchar_t
*ret
;
1550 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1551 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1552 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1554 if (!str
) str
= *next_token
;
1556 while (*str
&& strchrW( delim
, *str
)) str
++;
1557 if (!*str
) return NULL
;
1559 while (*str
&& !strchrW( delim
, *str
)) str
++;
1560 if (*str
) *str
++ = 0;
1565 /*********************************************************************
1568 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1570 return MSVCRT_wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1573 /*********************************************************************
1574 * _wctomb_s_l (MSVCRT.@)
1576 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1577 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1579 MSVCRT_pthreadlocinfo locinfo
;
1583 if(!mbchar
&& size
>0) {
1592 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1593 return MSVCRT_EINVAL
;
1596 locinfo
= get_locinfo();
1598 locinfo
= locale
->locinfo
;
1600 if(!locinfo
->lc_codepage
) {
1602 if(mbchar
&& size
>0)
1603 memset(mbchar
, 0, size
);
1604 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1605 return MSVCRT_EILSEQ
;
1608 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1609 return MSVCRT_ERANGE
;
1617 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1618 if(!mblen
|| error
) {
1619 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1620 if(mbchar
&& size
>0)
1621 memset(mbchar
, 0, size
);
1623 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1624 return MSVCRT_ERANGE
;
1627 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1628 return MSVCRT_EILSEQ
;
1636 /*********************************************************************
1637 * wctomb_s (MSVCRT.@)
1639 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1641 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1644 /*********************************************************************
1645 * _wctomb_l (MSVCRT.@)
1647 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1651 MSVCRT__wctomb_s_l(&len
, dst
, dst
? MSVCRT_MB_LEN_MAX
: 0, ch
, locale
);
1655 /*********************************************************************
1658 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1660 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1663 /*********************************************************************
1666 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1670 UINT codepage
= get_locinfo()->lc_codepage
;
1674 return (signed char)wchar
;
1677 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1682 /*********************************************************************
1683 * wcrtomb (MSVCRT.@)
1685 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1689 return MSVCRT_wctomb(dst
, ch
);
1692 /*********************************************************************
1693 * iswalnum (MSVCRT.@)
1695 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1697 return isalnumW( wc
);
1700 /*********************************************************************
1701 * iswalpha (MSVCRT.@)
1703 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1705 return isalphaW( wc
);
1708 /*********************************************************************
1709 * iswalpha_l (MSVCRT.@)
1711 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1713 return isalphaW( wc
);
1716 /*********************************************************************
1717 * iswcntrl (MSVCRT.@)
1719 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1721 return iscntrlW( wc
);
1724 /*********************************************************************
1725 * iswdigit (MSVCRT.@)
1727 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1729 return isdigitW( wc
);
1732 /*********************************************************************
1733 * _iswdigit_l (MSVCRT.@)
1735 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1737 return isdigitW( wc
);
1740 /*********************************************************************
1741 * iswgraph (MSVCRT.@)
1743 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1745 return isgraphW( wc
);
1748 /*********************************************************************
1749 * iswlower (MSVCRT.@)
1751 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1753 return islowerW( wc
);
1756 /*********************************************************************
1757 * iswprint (MSVCRT.@)
1759 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1761 return isprintW( wc
);
1764 /*********************************************************************
1765 * _iswpunct_l (MSVCRT.@)
1767 INT CDECL
MSVCRT__iswpunct_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1769 return ispunctW( wc
);
1772 /*********************************************************************
1773 * iswpunct (MSVCRT.@)
1775 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1777 return ispunctW( wc
);
1780 /*********************************************************************
1781 * _iswspace_l (MSVCRT.@)
1783 INT CDECL
MSVCRT__iswspace_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1785 return isspaceW( wc
);
1788 /*********************************************************************
1789 * iswspace (MSVCRT.@)
1791 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1793 return isspaceW( wc
);
1796 /*********************************************************************
1797 * iswupper (MSVCRT.@)
1799 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1801 return isupperW( wc
);
1804 /*********************************************************************
1805 * iswxdigit (MSVCRT.@)
1807 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1809 return isxdigitW( wc
);
1812 /*********************************************************************
1813 * wcscpy_s (MSVCRT.@)
1815 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1817 MSVCRT_size_t size
= 0;
1819 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1820 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1824 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1826 size
= strlenW(wcSrc
) + 1;
1828 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1829 return MSVCRT_ERANGE
;
1831 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1836 /******************************************************************
1837 * wcsncpy (MSVCRT.@)
1839 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1840 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1845 if(!(s1
[i
] = s2
[i
])) break;
1851 /******************************************************************
1852 * wcsncpy_s (MSVCRT.@)
1854 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1855 MSVCRT_size_t count
)
1858 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1860 if(!wcDest
&& !numElement
&& !count
)
1863 if (!wcDest
|| !numElement
)
1864 return MSVCRT_EINVAL
;
1869 return count
? MSVCRT_EINVAL
: 0;
1872 while (numElement
&& count
&& *wcSrc
)
1878 if (!numElement
&& truncate
)
1881 return MSVCRT_STRUNCATE
;
1883 else if (!numElement
)
1886 return MSVCRT_ERANGE
;
1893 /******************************************************************
1894 * wcscat_s (MSVCRT.@)
1897 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
1899 MSVCRT_wchar_t
* ptr
= dst
;
1901 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
1905 return MSVCRT_EINVAL
;
1908 /* seek to end of dst string (or elem if no end of string is found */
1909 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
1910 while (ptr
< dst
+ elem
)
1912 if ((*ptr
++ = *src
++) == '\0') return 0;
1914 /* not enough space */
1916 return MSVCRT_ERANGE
;
1919 /*********************************************************************
1920 * wcsncat_s (MSVCRT.@)
1923 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
1924 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
1926 MSVCRT_size_t srclen
;
1927 MSVCRT_wchar_t dststart
;
1930 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1931 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
1932 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
1937 for (dststart
= 0; dststart
< elem
; dststart
++)
1939 if (dst
[dststart
] == '\0')
1942 if (dststart
== elem
)
1944 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
1945 return MSVCRT_EINVAL
;
1948 if (count
== MSVCRT__TRUNCATE
)
1950 srclen
= strlenW(src
);
1951 if (srclen
>= (elem
- dststart
))
1953 srclen
= elem
- dststart
- 1;
1954 ret
= MSVCRT_STRUNCATE
;
1958 srclen
= min(strlenW(src
), count
);
1959 if (srclen
< (elem
- dststart
))
1961 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
1962 dst
[dststart
+srclen
] = '\0';
1965 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
1967 return MSVCRT_ERANGE
;
1970 /*********************************************************************
1971 * _wcstoi64_l (MSVCRT.@)
1973 * FIXME: locale parameter is ignored
1975 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
1976 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1978 BOOL negative
= FALSE
;
1981 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1983 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1984 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1985 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1987 while(isspaceW(*nptr
)) nptr
++;
1992 } else if(*nptr
== '+')
1995 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
2008 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
2011 if(cur
>='0' && cur
<='9') {
2016 if(cur
<'a' || cur
>='a'+base
-10)
2026 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
2027 ret
= MSVCRT_I64_MAX
;
2028 *MSVCRT__errno() = MSVCRT_ERANGE
;
2029 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
2030 ret
= MSVCRT_I64_MIN
;
2031 *MSVCRT__errno() = MSVCRT_ERANGE
;
2037 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2042 /*********************************************************************
2043 * _wcstoi64 (MSVCRT.@)
2045 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
2046 MSVCRT_wchar_t
**endptr
, int base
)
2048 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
2051 /*********************************************************************
2052 * _wcstol_l (MSVCRT.@)
2054 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
2055 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2057 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
2059 if(ret
> MSVCRT_LONG_MAX
) {
2060 ret
= MSVCRT_LONG_MAX
;
2061 *MSVCRT__errno() = MSVCRT_ERANGE
;
2062 }else if(ret
< MSVCRT_LONG_MIN
) {
2063 ret
= MSVCRT_LONG_MIN
;
2064 *MSVCRT__errno() = MSVCRT_ERANGE
;
2069 /*********************************************************************
2070 * _wtoi_l (MSVCRT.@)
2072 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2074 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2078 *MSVCRT__errno() = MSVCRT_ERANGE
;
2079 } else if(ret
< INT_MIN
) {
2081 *MSVCRT__errno() = MSVCRT_ERANGE
;
2086 /*********************************************************************
2089 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
2091 return MSVCRT__wtoi_l(str
, NULL
);
2094 /*********************************************************************
2095 * _wtol_l (MSVCRT.@)
2097 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2099 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2101 if(ret
> MSVCRT_LONG_MAX
) {
2102 ret
= MSVCRT_LONG_MAX
;
2103 *MSVCRT__errno() = MSVCRT_ERANGE
;
2104 } else if(ret
< MSVCRT_LONG_MIN
) {
2105 ret
= MSVCRT_LONG_MIN
;
2106 *MSVCRT__errno() = MSVCRT_ERANGE
;
2111 /*********************************************************************
2114 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
2116 return MSVCRT__wtol_l(str
, NULL
);
2119 /*********************************************************************
2120 * _wtoll_l (MSVCR120.@)
2122 MSVCRT_longlong __cdecl
MSVCRT__wtoll_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2124 return MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2127 /*********************************************************************
2128 * _wtoll (MSVCR120.@)
2130 MSVCRT_longlong __cdecl
MSVCRT__wtoll(const MSVCRT_wchar_t
*str
)
2132 return MSVCRT__wtoll_l(str
, NULL
);
2135 /*********************************************************************
2136 * _wcstoui64_l (MSVCRT.@)
2138 * FIXME: locale parameter is ignored
2140 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
2141 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2143 BOOL negative
= FALSE
;
2144 unsigned __int64 ret
= 0;
2146 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2148 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2149 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2150 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2152 while(isspaceW(*nptr
)) nptr
++;
2157 } else if(*nptr
== '+')
2160 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
2173 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
2176 if(cur
>='0' && cur
<='9') {
2181 if(cur
<'a' || cur
>='a'+base
-10)
2188 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
2189 ret
= MSVCRT_UI64_MAX
;
2190 *MSVCRT__errno() = MSVCRT_ERANGE
;
2196 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2198 return negative
? -ret
: ret
;
2201 /*********************************************************************
2202 * _wcstoui64 (MSVCRT.@)
2204 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
2205 MSVCRT_wchar_t
**endptr
, int base
)
2207 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
2210 /*********************************************************************
2211 * _wcstoul_l (MSVCRT.@)
2213 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
2214 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2216 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
2218 if(ret
> MSVCRT_ULONG_MAX
) {
2219 ret
= MSVCRT_ULONG_MAX
;
2220 *MSVCRT__errno() = MSVCRT_ERANGE
;
2225 /*********************************************************************
2226 * wcstoul (MSVCRT.@)
2228 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
2230 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
2233 /******************************************************************
2234 * wcsnlen (MSVCRT.@)
2236 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
2240 for (i
= 0; i
< maxlen
; i
++)
2245 /*********************************************************************
2246 * _towupper_l (MSVCRT.@)
2248 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2253 /*********************************************************************
2254 * towupper (MSVCRT.@)
2256 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
2258 return MSVCRT__towupper_l(c
, NULL
);
2261 /*********************************************************************
2262 * _towlower_l (MSVCRT.@)
2264 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2269 /*********************************************************************
2270 * towlower (MSVCRT.@)
2272 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
2274 return MSVCRT__towlower_l(c
, NULL
);
2277 /*********************************************************************
2280 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
2282 return strchrW(str
, ch
);
2285 /***********************************************************************
2288 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
2290 return strlenW(str
);
2293 /*********************************************************************
2296 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
2298 return strstrW(str
, sub
);
2301 /*********************************************************************
2302 * _wtoi64_l (MSVCRT.@)
2304 __int64 CDECL
MSVCRT__wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2306 ULONGLONG RunningTotal
= 0;
2307 BOOL bMinus
= FALSE
;
2309 while (isspaceW(*str
)) {
2315 } else if (*str
== '-') {
2320 while (*str
>= '0' && *str
<= '9') {
2321 RunningTotal
= RunningTotal
* 10 + *str
- '0';
2325 return bMinus
? -RunningTotal
: RunningTotal
;
2328 /*********************************************************************
2329 * _wtoi64 (MSVCRT.@)
2331 __int64 CDECL
MSVCRT__wtoi64(const MSVCRT_wchar_t
*str
)
2333 return MSVCRT__wtoi64_l(str
, NULL
);
2336 /*********************************************************************
2337 * wcsncmp (MSVCRT.@)
2339 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
2341 return strncmpW(str1
, str2
, n
);
2344 /*********************************************************************
2345 * _wcsxfrm_l (MSVCRT.@)
2347 MSVCRT_size_t CDECL
MSVCRT__wcsxfrm_l(MSVCRT_wchar_t
*dest
, const MSVCRT_wchar_t
*src
,
2348 MSVCRT_size_t len
, MSVCRT__locale_t locale
)
2350 MSVCRT_pthreadlocinfo locinfo
;
2353 if(!MSVCRT_CHECK_PMT(src
)) return INT_MAX
;
2354 if(!MSVCRT_CHECK_PMT(dest
|| !len
)) return INT_MAX
;
2357 FIXME("len > INT_MAX not supported\n");
2362 locinfo
= get_locinfo();
2364 locinfo
= locale
->locinfo
;
2366 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]) {
2367 MSVCRT_wcsncpy(dest
, src
, len
);
2368 return strlenW(src
);
2371 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2372 LCMAP_SORTKEY
, src
, -1, NULL
, 0);
2374 if(len
) dest
[0] = 0;
2375 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2378 if(!len
) return ret
-1;
2382 *MSVCRT__errno() = MSVCRT_ERANGE
;
2386 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2387 LCMAP_SORTKEY
, src
, -1, dest
, len
) - 1;
2388 for(i
=ret
; i
>=0; i
--)
2389 dest
[i
] = ((unsigned char*)dest
)[i
];
2393 /*********************************************************************
2394 * wcsxfrm (MSVCRT.@)
2396 MSVCRT_size_t CDECL
MSVCRT_wcsxfrm(MSVCRT_wchar_t
*dest
,
2397 const MSVCRT_wchar_t
*src
, MSVCRT_size_t len
)
2399 return MSVCRT__wcsxfrm_l(dest
, src
, len
, NULL
);