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
);
669 /*********************************************************************
670 * _wcstof_l (MSVCR120.@)
672 float CDECL
MSVCRT__wcstof_l( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
, MSVCRT__locale_t locale
)
674 return MSVCRT__wcstod_l(str
, end
, locale
);
677 /*********************************************************************
678 * wcstof (MSVCR120.@)
680 float CDECL
MSVCRT_wcstof( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
)
682 return MSVCRT__wcstof_l(str
, end
, NULL
);
685 #endif /* _MSVCR_VER>=120 */
687 /*********************************************************************
688 * arg_clbk_valist (INTERNAL)
690 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
695 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
696 else if(type
== VT_INT
)
697 ret
.get_int
= va_arg(*valist
, int);
698 else if(type
== VT_R8
)
699 ret
.get_double
= va_arg(*valist
, double);
700 else if(type
== VT_PTR
)
701 ret
.get_ptr
= va_arg(*valist
, void*);
703 ERR("Incorrect type\n");
710 /*********************************************************************
711 * arg_clbk_positional (INTERNAL)
713 printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
715 printf_arg
*args
= ctx
;
719 /*********************************************************************
720 * _vsnprintf (MSVCRT.@)
722 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
723 const char *format
, __ms_va_list valist
)
725 static const char nullbyte
= '\0';
726 struct _str_ctx_a ctx
= {len
, str
};
729 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, 0,
730 arg_clbk_valist
, NULL
, &valist
);
731 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
737 static int puts_clbk_str_c99_a(void *ctx
, int len
, const char *str
)
739 struct _str_ctx_a
*out
= ctx
;
745 memcpy(out
->buf
, str
, out
->len
);
746 out
->buf
+= out
->len
;
751 memcpy(out
->buf
, str
, len
);
757 /*********************************************************************
758 * __stdio_common_vsprintf (UCRTBASE.@)
760 int CDECL
MSVCRT__stdio_common_vsprintf( unsigned __int64 options
, char *str
, MSVCRT_size_t len
, const char *format
,
761 MSVCRT__locale_t locale
, __ms_va_list valist
)
763 static const char nullbyte
= '\0';
764 struct _str_ctx_a ctx
= {len
, str
};
767 if (options
& ~UCRTBASE_PRINTF_MASK
)
768 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
769 ret
= pf_printf_a(puts_clbk_str_c99_a
,
770 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
771 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
775 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
776 return ret
>len
? -1 : ret
;
778 if(len
) str
[len
-1] = 0;
779 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
784 #endif /* _MSVCR_VER>=140 */
786 /*********************************************************************
787 * _vsnprintf_l (MSVCRT.@)
789 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
790 MSVCRT__locale_t locale
, __ms_va_list valist
)
792 static const char nullbyte
= '\0';
793 struct _str_ctx_a ctx
= {len
, str
};
796 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, 0,
797 arg_clbk_valist
, NULL
, &valist
);
798 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
802 /*********************************************************************
803 * _vsprintf_l (MSVCRT.@)
805 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
806 MSVCRT__locale_t locale
, __ms_va_list valist
)
808 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
811 /*********************************************************************
812 * _sprintf_l (MSVCRT.@)
814 int WINAPIV
MSVCRT_sprintf_l(char *str
, const char *format
,
815 MSVCRT__locale_t locale
, ...)
819 __ms_va_start(valist
, locale
);
820 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
825 static int CDECL
MSVCRT_vsnprintf_s_l_opt( char *str
, MSVCRT_size_t sizeOfBuffer
,
826 MSVCRT_size_t count
, const char *format
, DWORD options
,
827 MSVCRT__locale_t locale
, __ms_va_list valist
)
829 static const char nullbyte
= '\0';
830 struct _str_ctx_a ctx
;
833 if(sizeOfBuffer
<count
+1 || count
==-1)
840 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
841 arg_clbk_valist
, NULL
, &valist
);
842 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
844 if(ret
<0 || ret
==len
) {
845 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
846 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
847 memset(str
, 0, sizeOfBuffer
);
857 static int MSVCRT_vsnwprintf_s_l_opt( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
858 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, DWORD options
,
859 MSVCRT__locale_t locale
, __ms_va_list valist
)
861 static const MSVCRT_wchar_t nullbyte
= '\0';
862 struct _str_ctx_w ctx
;
866 if(count
!=-1 && len
>count
+1)
871 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
872 arg_clbk_valist
, NULL
, &valist
);
873 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
875 if(ret
<0 || ret
==len
) {
876 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
877 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
878 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
888 /*********************************************************************
889 * _vsnprintf_s_l (MSVCRT.@)
891 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
892 MSVCRT_size_t count
, const char *format
,
893 MSVCRT__locale_t locale
, __ms_va_list valist
)
895 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
898 /*********************************************************************
899 * _vsprintf_s_l (MSVCRT.@)
901 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
902 MSVCRT__locale_t locale
, __ms_va_list valist
)
904 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
907 /*********************************************************************
908 * _sprintf_s_l (MSVCRT.@)
910 int WINAPIV
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
911 MSVCRT__locale_t locale
, ...)
915 __ms_va_start(valist
, locale
);
916 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
921 /*********************************************************************
922 * _vsnprintf_s (MSVCRT.@)
924 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
925 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
927 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
932 /*********************************************************************
933 * __stdio_common_vsnprintf_s (UCRTBASE.@)
935 int CDECL
MSVCRT__stdio_common_vsnprintf_s( unsigned __int64 options
,
936 char *str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
937 const char *format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
939 if (options
& ~UCRTBASE_PRINTF_MASK
)
940 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
941 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
944 /*********************************************************************
945 * __stdio_common_vsnwprintf_s (UCRTBASE.@)
947 int CDECL
MSVCRT__stdio_common_vsnwprintf_s( unsigned __int64 options
,
948 MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
949 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
951 if (options
& ~UCRTBASE_PRINTF_MASK
)
952 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
953 return MSVCRT_vsnwprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
956 /*********************************************************************
957 * __stdio_common_vswprintf_s (UCRTBASE.@)
959 int CDECL
MSVCRT__stdio_common_vswprintf_s( unsigned __int64 options
,
960 MSVCRT_wchar_t
*str
, MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
961 MSVCRT__locale_t locale
, __ms_va_list valist
)
963 return MSVCRT__stdio_common_vsnwprintf_s(options
, str
, INT_MAX
, count
, format
, locale
, valist
);
966 /*********************************************************************
967 * __stdio_common_vsprintf_s (UCRTBASE.@)
969 int CDECL
MSVCRT__stdio_common_vsprintf_s( unsigned __int64 options
,
970 char *str
, MSVCRT_size_t count
, const char *format
,
971 MSVCRT__locale_t locale
, __ms_va_list valist
)
973 if (options
& ~UCRTBASE_PRINTF_MASK
)
974 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
975 return MSVCRT_vsnprintf_s_l_opt(str
, INT_MAX
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
978 #endif /* _MSVCR_VER>=140 */
980 /*********************************************************************
981 * vsprintf (MSVCRT.@)
983 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
985 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
988 /*********************************************************************
989 * vsprintf_s (MSVCRT.@)
991 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
993 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
996 /*********************************************************************
997 * _vscprintf (MSVCRT.@)
999 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
1001 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
1004 /*********************************************************************
1005 * _vscprintf_p_l (MSVCRT.@)
1007 int CDECL
MSVCRT__vscprintf_p_l(const char *format
,
1008 MSVCRT__locale_t locale
, __ms_va_list args
)
1010 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1011 struct _str_ctx_a puts_ctx
= {INT_MAX
, NULL
};
1014 memset(args_ctx
, 0, sizeof(args_ctx
));
1016 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1018 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1019 *MSVCRT__errno() = MSVCRT_EINVAL
;
1021 } else if(ret
== 0) {
1022 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1023 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1024 arg_clbk_valist
, NULL
, &args
);
1026 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1027 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1028 arg_clbk_positional
, args_ctx
, NULL
);
1034 /*********************************************************************
1035 * _vscprintf_p (MSVCR80.@)
1037 int CDECL
MSVCRT__vscprintf_p(const char *format
, __ms_va_list argptr
)
1039 return MSVCRT__vscprintf_p_l(format
, NULL
, argptr
);
1042 /*********************************************************************
1043 * _snprintf (MSVCRT.@)
1045 int WINAPIV
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
1048 __ms_va_list valist
;
1049 __ms_va_start(valist
, format
);
1050 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
1051 __ms_va_end(valist
);
1055 /*********************************************************************
1056 * _snprintf_l (MSVCRT.@)
1058 int WINAPIV
MSVCRT__snprintf_l(char *str
, unsigned int count
, MSVCRT__locale_t locale
,
1059 const char *format
, ...)
1062 __ms_va_list valist
;
1063 __ms_va_start(valist
, format
);
1064 retval
= MSVCRT_vsnprintf_l(str
, count
, format
, locale
, valist
);
1065 __ms_va_end(valist
);
1069 /*********************************************************************
1070 * _snprintf_s (MSVCRT.@)
1072 int WINAPIV
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
1073 const char *format
, ...)
1076 __ms_va_list valist
;
1077 __ms_va_start(valist
, format
);
1078 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1079 __ms_va_end(valist
);
1083 /*********************************************************************
1084 * _scprintf (MSVCRT.@)
1086 int WINAPIV
MSVCRT__scprintf(const char *format
, ...)
1089 __ms_va_list valist
;
1090 __ms_va_start(valist
, format
);
1091 retval
= MSVCRT__vscprintf(format
, valist
);
1092 __ms_va_end(valist
);
1096 /*********************************************************************
1097 * _vsnwprintf (MSVCRT.@)
1099 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1100 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1102 static const MSVCRT_wchar_t nullbyte
= '\0';
1103 struct _str_ctx_w ctx
= {len
, str
};
1106 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, 0,
1107 arg_clbk_valist
, NULL
, &valist
);
1108 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1112 /*********************************************************************
1113 * _vsnwprintf_l (MSVCRT.@)
1115 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1116 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
1117 __ms_va_list valist
)
1119 static const MSVCRT_wchar_t nullbyte
= '\0';
1120 struct _str_ctx_w ctx
= {len
, str
};
1123 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, 0,
1124 arg_clbk_valist
, NULL
, &valist
);
1125 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1129 static int MSVCRT_vswprintf_p_l_opt(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1130 const MSVCRT_wchar_t
*format
, DWORD options
, MSVCRT__locale_t locale
, __ms_va_list args
)
1132 static const MSVCRT_wchar_t nullbyte
= '\0';
1133 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1134 struct _str_ctx_w puts_ctx
= {length
, buffer
};
1137 memset(args_ctx
, 0, sizeof(args_ctx
));
1139 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
1141 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1142 *MSVCRT__errno() = MSVCRT_EINVAL
;
1145 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1146 arg_clbk_valist
, NULL
, &args
);
1148 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
,
1149 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1150 arg_clbk_positional
, args_ctx
, NULL
);
1152 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
1156 /*********************************************************************
1157 * _vswprintf_p_l (MSVCRT.@)
1159 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1160 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1162 return MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, locale
, args
);
1166 /*********************************************************************
1167 * _vswprintf_p (MSVCR80.@)
1169 int CDECL
MSVCRT__vswprintf_p(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1170 const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1172 return MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, NULL
, args
);
1177 /*********************************************************************
1178 * __stdio_common_vswprintf_p (UCRTBASE.@)
1180 int CDECL
MSVCRT__stdio_common_vswprintf_p( unsigned __int64 options
,
1181 MSVCRT_wchar_t
*str
, MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1182 MSVCRT__locale_t locale
, __ms_va_list valist
)
1184 if (options
& ~UCRTBASE_PRINTF_MASK
)
1185 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1186 return MSVCRT_vswprintf_p_l_opt(str
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
1190 /*********************************************************************
1191 * _vsnwprintf_s_l (MSVCRT.@)
1193 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1194 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1195 MSVCRT__locale_t locale
, __ms_va_list valist
)
1197 return MSVCRT_vsnwprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
1200 /*********************************************************************
1201 * _vsnwprintf_s (MSVCRT.@)
1203 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1204 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1206 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
1207 format
, NULL
, valist
);
1210 /*********************************************************************
1211 * _snwprintf (MSVCRT.@)
1213 int WINAPIV
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
1216 __ms_va_list valist
;
1217 __ms_va_start(valist
, format
);
1218 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
1219 __ms_va_end(valist
);
1223 /*********************************************************************
1224 * _snwprintf_l (MSVCRT.@)
1226 int WINAPIV
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
1227 MSVCRT__locale_t locale
, ...)
1230 __ms_va_list valist
;
1231 __ms_va_start(valist
, locale
);
1232 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
1233 __ms_va_end(valist
);
1237 /*********************************************************************
1238 * _snwprintf_s (MSVCRT.@)
1240 int WINAPIV
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1241 const MSVCRT_wchar_t
*format
, ...)
1244 __ms_va_list valist
;
1245 __ms_va_start(valist
, format
);
1246 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1247 __ms_va_end(valist
);
1251 /*********************************************************************
1252 * _snwprintf_s_l (MSVCRT.@)
1254 int WINAPIV
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1255 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1258 __ms_va_list valist
;
1259 __ms_va_start(valist
, locale
);
1260 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
1261 __ms_va_end(valist
);
1267 static int puts_clbk_str_c99_w(void *ctx
, int len
, const MSVCRT_wchar_t
*str
)
1269 struct _str_ctx_w
*out
= ctx
;
1274 if(out
->len
< len
) {
1275 memcpy(out
->buf
, str
, out
->len
*sizeof(MSVCRT_wchar_t
));
1276 out
->buf
+= out
->len
;
1281 memcpy(out
->buf
, str
, len
*sizeof(MSVCRT_wchar_t
));
1287 /*********************************************************************
1288 * __stdio_common_vswprintf (UCRTBASE.@)
1290 int CDECL
MSVCRT__stdio_common_vswprintf( unsigned __int64 options
,
1291 MSVCRT_wchar_t
*str
, MSVCRT_size_t len
, const MSVCRT_wchar_t
*format
,
1292 MSVCRT__locale_t locale
, __ms_va_list valist
)
1294 static const MSVCRT_wchar_t nullbyte
= '\0';
1295 struct _str_ctx_w ctx
= {len
, str
};
1298 if (options
& ~UCRTBASE_PRINTF_MASK
)
1299 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1300 ret
= pf_printf_w(puts_clbk_str_c99_w
,
1301 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
1302 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1306 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
1307 return ret
>len
? -1 : ret
;
1309 if(len
) str
[len
-1] = 0;
1310 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
1315 #endif /* _MSVCR_VER>=140 */
1317 /*********************************************************************
1318 * sprintf (MSVCRT.@)
1320 int WINAPIV
MSVCRT_sprintf( char *str
, const char *format
, ... )
1325 __ms_va_start( ap
, format
);
1326 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
1331 /*********************************************************************
1332 * sprintf_s (MSVCRT.@)
1334 int WINAPIV
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
1339 __ms_va_start( ap
, format
);
1340 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
1345 /*********************************************************************
1346 * _scwprintf (MSVCRT.@)
1348 int WINAPIV
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
1353 __ms_va_start( ap
, format
);
1354 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1359 /*********************************************************************
1360 * swprintf (MSVCRT.@)
1362 int WINAPIV
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1367 __ms_va_start( ap
, format
);
1368 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1373 /*********************************************************************
1374 * swprintf_s (MSVCRT.@)
1376 int WINAPIV
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1377 const MSVCRT_wchar_t
*format
, ... )
1382 __ms_va_start(ap
, format
);
1383 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1389 /*********************************************************************
1390 * _swprintf_s_l (MSVCRT.@)
1392 int WINAPIV
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1393 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1398 __ms_va_start(ap
, locale
);
1399 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1405 /*********************************************************************
1406 * _vswprintf (MSVCRT.@)
1408 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1410 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1413 /*********************************************************************
1414 * _vswprintf (MSVCRT.@)
1416 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1417 MSVCRT__locale_t locale
, __ms_va_list args
)
1419 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1422 /*********************************************************************
1423 * _vscwprintf (MSVCRT.@)
1425 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1427 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1430 /*********************************************************************
1431 * _vscwprintf_l (MSVCRT.@)
1433 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1435 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1438 /*********************************************************************
1439 * _vscwprintf_p_l (MSVCRT.@)
1441 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1443 return MSVCRT_vswprintf_p_l_opt( NULL
, INT_MAX
, format
, 0, locale
, args
);
1447 /*********************************************************************
1448 * _vscwprintf_p (MSVCR80.@)
1450 int CDECL
MSVCRT__vscwprintf_p(const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1452 return MSVCRT_vswprintf_p_l_opt(NULL
, INT_MAX
, format
, 0, NULL
, args
);
1456 /*********************************************************************
1457 * vswprintf_s (MSVCRT.@)
1459 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1460 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1462 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1465 /*********************************************************************
1466 * _vswprintf_s_l (MSVCRT.@)
1468 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1469 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1471 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1472 format
, locale
, args
);
1475 static int MSVCRT_vsprintf_p_l_opt(char *buffer
, MSVCRT_size_t length
, const char *format
,
1476 DWORD options
, MSVCRT__locale_t locale
, __ms_va_list args
)
1478 static const char nullbyte
= '\0';
1479 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1480 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1483 memset(args_ctx
, 0, sizeof(args_ctx
));
1485 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1487 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1488 *MSVCRT__errno() = MSVCRT_EINVAL
;
1491 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1492 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
, arg_clbk_valist
, NULL
, &args
);
1494 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1495 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1496 arg_clbk_positional
, args_ctx
, NULL
);
1498 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1502 /*********************************************************************
1503 * _vsprintf_p_l (MSVCRT.@)
1505 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1506 MSVCRT__locale_t locale
, __ms_va_list args
)
1508 return MSVCRT_vsprintf_p_l_opt(buffer
, length
, format
, 0, locale
, args
);
1511 /*********************************************************************
1512 * _vsprintf_p (MSVCRT.@)
1514 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1515 const char *format
, __ms_va_list args
)
1517 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1521 /*********************************************************************
1522 * __stdio_common_vsprintf_p (UCRTBASE.@)
1524 int CDECL
MSVCRT__stdio_common_vsprintf_p(unsigned __int64 options
, char *buffer
, MSVCRT_size_t length
,
1525 const char *format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1527 if (options
& ~UCRTBASE_PRINTF_MASK
)
1528 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1529 return MSVCRT_vsprintf_p_l_opt(buffer
, length
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, args
);
1533 /*********************************************************************
1534 * _sprintf_p_l (MSVCRT.@)
1536 int WINAPIV
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1537 const char *format
, MSVCRT__locale_t locale
, ...)
1539 __ms_va_list valist
;
1542 __ms_va_start(valist
, locale
);
1543 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1544 __ms_va_end(valist
);
1549 /*********************************************************************
1550 * __swprintf_l (MSVCRT.@)
1552 int WINAPIV
MSVCRT___swprintf_l( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
1553 MSVCRT__locale_t locale
, ...)
1556 __ms_va_list valist
;
1557 __ms_va_start(valist
, locale
);
1558 retval
= MSVCRT_vswprintf_l(str
, format
, locale
, valist
);
1559 __ms_va_end(valist
);
1564 /*********************************************************************
1565 * _sprintf_p (MSVCR80.@)
1567 int WINAPIV
MSVCRT__sprintf_p(char *buffer
, MSVCRT_size_t length
, const char *format
, ...)
1569 __ms_va_list valist
;
1572 __ms_va_start(valist
, format
);
1573 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, valist
);
1574 __ms_va_end(valist
);
1580 /*********************************************************************
1581 * _swprintf_p_l (MSVCRT.@)
1583 int WINAPIV
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1584 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1586 __ms_va_list valist
;
1589 __ms_va_start(valist
, locale
);
1590 r
= MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, locale
, valist
);
1591 __ms_va_end(valist
);
1596 /*********************************************************************
1597 * _wcscoll_l (MSVCRT.@)
1599 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1601 MSVCRT_pthreadlocinfo locinfo
;
1604 locinfo
= get_locinfo();
1606 locinfo
= locale
->locinfo
;
1608 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1609 return strcmpW(str1
, str2
);
1610 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1613 /*********************************************************************
1614 * wcscoll (MSVCRT.@)
1616 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1618 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1621 /*********************************************************************
1622 * wcspbrk (MSVCRT.@)
1624 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1626 const MSVCRT_wchar_t
* p
;
1630 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1636 /*********************************************************************
1637 * wcstok_s (MSVCRT.@)
1639 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1640 MSVCRT_wchar_t
**next_token
)
1642 MSVCRT_wchar_t
*ret
;
1644 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1645 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1646 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1648 if (!str
) str
= *next_token
;
1650 while (*str
&& strchrW( delim
, *str
)) str
++;
1651 if (!*str
) return NULL
;
1653 while (*str
&& !strchrW( delim
, *str
)) str
++;
1654 if (*str
) *str
++ = 0;
1659 /*********************************************************************
1662 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1664 return MSVCRT_wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1667 /*********************************************************************
1668 * _wctomb_s_l (MSVCRT.@)
1670 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1671 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1673 MSVCRT_pthreadlocinfo locinfo
;
1677 if(!mbchar
&& size
>0) {
1686 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1687 return MSVCRT_EINVAL
;
1690 locinfo
= get_locinfo();
1692 locinfo
= locale
->locinfo
;
1694 if(!locinfo
->lc_codepage
) {
1696 if(mbchar
&& size
>0)
1697 memset(mbchar
, 0, size
);
1698 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1699 return MSVCRT_EILSEQ
;
1702 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1703 return MSVCRT_ERANGE
;
1711 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1712 if(!mblen
|| error
) {
1713 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1714 if(mbchar
&& size
>0)
1715 memset(mbchar
, 0, size
);
1717 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1718 return MSVCRT_ERANGE
;
1721 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1722 return MSVCRT_EILSEQ
;
1730 /*********************************************************************
1731 * wctomb_s (MSVCRT.@)
1733 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1735 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1738 /*********************************************************************
1739 * _wctomb_l (MSVCRT.@)
1741 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1745 MSVCRT__wctomb_s_l(&len
, dst
, dst
? MSVCRT_MB_LEN_MAX
: 0, ch
, locale
);
1749 /*********************************************************************
1752 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1754 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1757 /*********************************************************************
1760 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1764 UINT codepage
= get_locinfo()->lc_codepage
;
1768 return (signed char)wchar
;
1771 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1776 /*********************************************************************
1777 * wcrtomb (MSVCRT.@)
1779 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1783 return MSVCRT_wctomb(dst
, ch
);
1786 /*********************************************************************
1787 * iswalnum (MSVCRT.@)
1789 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1791 return isalnumW( wc
);
1794 /*********************************************************************
1795 * iswalpha (MSVCRT.@)
1797 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1799 return isalphaW( wc
);
1802 /*********************************************************************
1803 * iswalpha_l (MSVCRT.@)
1805 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1807 return isalphaW( wc
);
1810 /*********************************************************************
1811 * iswcntrl (MSVCRT.@)
1813 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1815 return iscntrlW( wc
);
1818 /*********************************************************************
1819 * iswdigit (MSVCRT.@)
1821 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1823 return isdigitW( wc
);
1826 /*********************************************************************
1827 * _iswdigit_l (MSVCRT.@)
1829 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1831 return isdigitW( wc
);
1834 /*********************************************************************
1835 * iswgraph (MSVCRT.@)
1837 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1839 return isgraphW( wc
);
1842 /*********************************************************************
1843 * iswlower (MSVCRT.@)
1845 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1847 return islowerW( wc
);
1850 /*********************************************************************
1851 * iswprint (MSVCRT.@)
1853 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1855 return isprintW( wc
);
1858 /*********************************************************************
1859 * _iswpunct_l (MSVCRT.@)
1861 INT CDECL
MSVCRT__iswpunct_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1863 return ispunctW( wc
);
1866 /*********************************************************************
1867 * iswpunct (MSVCRT.@)
1869 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1871 return ispunctW( wc
);
1874 /*********************************************************************
1875 * _iswspace_l (MSVCRT.@)
1877 INT CDECL
MSVCRT__iswspace_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1879 return isspaceW( wc
);
1882 /*********************************************************************
1883 * iswspace (MSVCRT.@)
1885 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1887 return isspaceW( wc
);
1890 /*********************************************************************
1891 * iswupper (MSVCRT.@)
1893 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1895 return isupperW( wc
);
1898 /*********************************************************************
1899 * iswxdigit (MSVCRT.@)
1901 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1903 return isxdigitW( wc
);
1906 /*********************************************************************
1907 * _iswctype_l (MSVCRT.@)
1909 INT CDECL
MSVCRT__iswctype_l( MSVCRT_wchar_t wc
, MSVCRT_wctype_t type
, MSVCRT__locale_t locale
)
1911 return (get_char_typeW(wc
) & 0xffff) & type
;
1914 /*********************************************************************
1915 * _iswblank_l (MSVCRT.@)
1917 INT CDECL
MSVCRT__iswblank_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1919 return wc
== '\t' || MSVCRT__iswctype_l( wc
, MSVCRT__BLANK
, locale
);
1922 /*********************************************************************
1923 * iswblank (MSVCRT.@)
1925 INT CDECL
MSVCRT_iswblank( MSVCRT_wchar_t wc
)
1927 return wc
== '\t' || MSVCRT__iswctype_l( wc
, MSVCRT__BLANK
, NULL
);
1930 /*********************************************************************
1931 * wcscpy_s (MSVCRT.@)
1933 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1935 MSVCRT_size_t size
= 0;
1937 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1938 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1942 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1944 size
= strlenW(wcSrc
) + 1;
1946 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1947 return MSVCRT_ERANGE
;
1949 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1954 /******************************************************************
1955 * wcsncpy (MSVCRT.@)
1957 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1958 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1963 if(!(s1
[i
] = s2
[i
])) break;
1969 /******************************************************************
1970 * wcsncpy_s (MSVCRT.@)
1972 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1973 MSVCRT_size_t count
)
1976 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1978 if(!wcDest
&& !numElement
&& !count
)
1981 if (!wcDest
|| !numElement
)
1982 return MSVCRT_EINVAL
;
1987 return count
? MSVCRT_EINVAL
: 0;
1990 while (numElement
&& count
&& *wcSrc
)
1996 if (!numElement
&& truncate
)
1999 return MSVCRT_STRUNCATE
;
2001 else if (!numElement
)
2004 return MSVCRT_ERANGE
;
2011 /******************************************************************
2012 * wcscat_s (MSVCRT.@)
2015 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
2017 MSVCRT_wchar_t
* ptr
= dst
;
2019 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
2023 return MSVCRT_EINVAL
;
2026 /* seek to end of dst string (or elem if no end of string is found */
2027 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
2028 while (ptr
< dst
+ elem
)
2030 if ((*ptr
++ = *src
++) == '\0') return 0;
2032 /* not enough space */
2034 return MSVCRT_ERANGE
;
2037 /*********************************************************************
2038 * wcsncat_s (MSVCRT.@)
2041 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
2042 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
2044 MSVCRT_size_t srclen
;
2045 MSVCRT_wchar_t dststart
;
2048 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
2049 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
2050 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
2055 for (dststart
= 0; dststart
< elem
; dststart
++)
2057 if (dst
[dststart
] == '\0')
2060 if (dststart
== elem
)
2062 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
2063 return MSVCRT_EINVAL
;
2066 if (count
== MSVCRT__TRUNCATE
)
2068 srclen
= strlenW(src
);
2069 if (srclen
>= (elem
- dststart
))
2071 srclen
= elem
- dststart
- 1;
2072 ret
= MSVCRT_STRUNCATE
;
2076 srclen
= min(strlenW(src
), count
);
2077 if (srclen
< (elem
- dststart
))
2079 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
2080 dst
[dststart
+srclen
] = '\0';
2083 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
2085 return MSVCRT_ERANGE
;
2088 /*********************************************************************
2089 * wctoint (INTERNAL)
2091 static int wctoint(WCHAR c
, int base
)
2094 if ('0' <= c
&& c
<= '9')
2096 else if ('A' <= c
&& c
<= 'Z')
2098 else if ('a' <= c
&& c
<= 'z')
2101 /* NOTE: wine_fold_string(MAP_FOLDDIGITS) supports too many things. */
2102 /* Unicode points that contain digits 0-9; keep this sorted! */
2103 static const WCHAR zeros
[] = {
2104 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
2105 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
2108 for (i
= 0; i
< sizeof(zeros
)/sizeof(zeros
[0]) && c
>= zeros
[i
]; ++i
) {
2109 if (zeros
[i
] <= c
&& c
<= zeros
[i
] + 9) {
2115 return v
< base
? v
: -1;
2118 /*********************************************************************
2119 * _wcstoi64_l (MSVCRT.@)
2121 * FIXME: locale parameter is ignored
2123 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
2124 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2126 BOOL negative
= FALSE
, empty
= TRUE
;
2129 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2131 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2132 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2133 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2136 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2138 while(isspaceW(*nptr
)) nptr
++;
2143 } else if(*nptr
== '+')
2146 if((base
==0 || base
==16) && wctoint(*nptr
, 1)==0 && tolowerW(*(nptr
+1))=='x') {
2152 if(wctoint(*nptr
, 1)==0)
2159 int v
= wctoint(*nptr
, base
);
2169 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
2170 ret
= MSVCRT_I64_MAX
;
2171 *MSVCRT__errno() = MSVCRT_ERANGE
;
2172 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
2173 ret
= MSVCRT_I64_MIN
;
2174 *MSVCRT__errno() = MSVCRT_ERANGE
;
2179 if(endptr
&& !empty
)
2180 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2185 /*********************************************************************
2186 * _wcstoi64 (MSVCRT.@)
2188 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
2189 MSVCRT_wchar_t
**endptr
, int base
)
2191 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
2194 /*********************************************************************
2195 * _wcstol_l (MSVCRT.@)
2197 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
2198 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2200 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
2202 if(ret
> MSVCRT_LONG_MAX
) {
2203 ret
= MSVCRT_LONG_MAX
;
2204 *MSVCRT__errno() = MSVCRT_ERANGE
;
2205 }else if(ret
< MSVCRT_LONG_MIN
) {
2206 ret
= MSVCRT_LONG_MIN
;
2207 *MSVCRT__errno() = MSVCRT_ERANGE
;
2212 /*********************************************************************
2213 * _wtoi_l (MSVCRT.@)
2215 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2217 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2221 *MSVCRT__errno() = MSVCRT_ERANGE
;
2222 } else if(ret
< INT_MIN
) {
2224 *MSVCRT__errno() = MSVCRT_ERANGE
;
2229 /*********************************************************************
2232 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
2234 return MSVCRT__wtoi_l(str
, NULL
);
2237 /*********************************************************************
2238 * _wtol_l (MSVCRT.@)
2240 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2242 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2244 if(ret
> MSVCRT_LONG_MAX
) {
2245 ret
= MSVCRT_LONG_MAX
;
2246 *MSVCRT__errno() = MSVCRT_ERANGE
;
2247 } else if(ret
< MSVCRT_LONG_MIN
) {
2248 ret
= MSVCRT_LONG_MIN
;
2249 *MSVCRT__errno() = MSVCRT_ERANGE
;
2254 /*********************************************************************
2257 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
2259 return MSVCRT__wtol_l(str
, NULL
);
2264 /*********************************************************************
2265 * _wtoll_l (MSVCR120.@)
2267 MSVCRT_longlong __cdecl
MSVCRT__wtoll_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2269 return MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2272 /*********************************************************************
2273 * _wtoll (MSVCR120.@)
2275 MSVCRT_longlong __cdecl
MSVCRT__wtoll(const MSVCRT_wchar_t
*str
)
2277 return MSVCRT__wtoll_l(str
, NULL
);
2280 #endif /* _MSVCR_VER>=120 */
2282 /*********************************************************************
2283 * _wcstoui64_l (MSVCRT.@)
2285 * FIXME: locale parameter is ignored
2287 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
2288 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2290 BOOL negative
= FALSE
, empty
= TRUE
;
2291 unsigned __int64 ret
= 0;
2293 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2295 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2296 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2297 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2300 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2302 while(isspaceW(*nptr
)) nptr
++;
2307 } else if(*nptr
== '+')
2310 if((base
==0 || base
==16) && wctoint(*nptr
, 1)==0 && tolowerW(*(nptr
+1))=='x') {
2316 if(wctoint(*nptr
, 1)==0)
2323 int v
= wctoint(*nptr
, base
);
2330 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
2331 ret
= MSVCRT_UI64_MAX
;
2332 *MSVCRT__errno() = MSVCRT_ERANGE
;
2337 if(endptr
&& !empty
)
2338 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2340 return negative
? -ret
: ret
;
2343 /*********************************************************************
2344 * _wcstoui64 (MSVCRT.@)
2346 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
2347 MSVCRT_wchar_t
**endptr
, int base
)
2349 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
2352 /*********************************************************************
2353 * _wcstoul_l (MSVCRT.@)
2355 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
2356 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2358 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
2360 if(ret
> MSVCRT_ULONG_MAX
) {
2361 ret
= MSVCRT_ULONG_MAX
;
2362 *MSVCRT__errno() = MSVCRT_ERANGE
;
2367 /*********************************************************************
2368 * wcstoul (MSVCRT.@)
2370 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
2372 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
2375 /******************************************************************
2376 * wcsnlen (MSVCRT.@)
2378 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
2382 for (i
= 0; i
< maxlen
; i
++)
2387 /*********************************************************************
2388 * _towupper_l (MSVCRT.@)
2390 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2395 /*********************************************************************
2396 * towupper (MSVCRT.@)
2398 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
2400 return MSVCRT__towupper_l(c
, NULL
);
2403 /*********************************************************************
2404 * _towlower_l (MSVCRT.@)
2406 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2411 /*********************************************************************
2412 * towlower (MSVCRT.@)
2414 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
2416 return MSVCRT__towlower_l(c
, NULL
);
2419 /*********************************************************************
2422 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
2424 return strchrW(str
, ch
);
2427 /***********************************************************************
2430 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
2432 return strlenW(str
);
2435 /*********************************************************************
2438 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
2440 return strstrW(str
, sub
);
2443 /*********************************************************************
2444 * _wtoi64_l (MSVCRT.@)
2446 __int64 CDECL
MSVCRT__wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2448 ULONGLONG RunningTotal
= 0;
2449 BOOL bMinus
= FALSE
;
2451 while (isspaceW(*str
)) {
2457 } else if (*str
== '-') {
2462 while (*str
>= '0' && *str
<= '9') {
2463 RunningTotal
= RunningTotal
* 10 + *str
- '0';
2467 return bMinus
? -RunningTotal
: RunningTotal
;
2470 /*********************************************************************
2471 * _wtoi64 (MSVCRT.@)
2473 __int64 CDECL
MSVCRT__wtoi64(const MSVCRT_wchar_t
*str
)
2475 return MSVCRT__wtoi64_l(str
, NULL
);
2478 /*********************************************************************
2479 * wcsncmp (MSVCRT.@)
2481 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
2483 return strncmpW(str1
, str2
, n
);
2486 /*********************************************************************
2487 * _wcsxfrm_l (MSVCRT.@)
2489 MSVCRT_size_t CDECL
MSVCRT__wcsxfrm_l(MSVCRT_wchar_t
*dest
, const MSVCRT_wchar_t
*src
,
2490 MSVCRT_size_t len
, MSVCRT__locale_t locale
)
2492 MSVCRT_pthreadlocinfo locinfo
;
2495 if(!MSVCRT_CHECK_PMT(src
)) return INT_MAX
;
2496 if(!MSVCRT_CHECK_PMT(dest
|| !len
)) return INT_MAX
;
2499 FIXME("len > INT_MAX not supported\n");
2504 locinfo
= get_locinfo();
2506 locinfo
= locale
->locinfo
;
2508 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]) {
2509 MSVCRT_wcsncpy(dest
, src
, len
);
2510 return strlenW(src
);
2513 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2514 LCMAP_SORTKEY
, src
, -1, NULL
, 0);
2516 if(len
) dest
[0] = 0;
2517 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2520 if(!len
) return ret
-1;
2524 *MSVCRT__errno() = MSVCRT_ERANGE
;
2528 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2529 LCMAP_SORTKEY
, src
, -1, dest
, len
) - 1;
2530 for(i
=ret
; i
>=0; i
--)
2531 dest
[i
] = ((unsigned char*)dest
)[i
];
2535 /*********************************************************************
2536 * wcsxfrm (MSVCRT.@)
2538 MSVCRT_size_t CDECL
MSVCRT_wcsxfrm(MSVCRT_wchar_t
*dest
,
2539 const MSVCRT_wchar_t
*src
, MSVCRT_size_t len
)
2541 return MSVCRT__wcsxfrm_l(dest
, src
, len
, NULL
);