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
;
45 /*********************************************************************
46 * _get_printf_count_output (MSVCR80.@)
48 int CDECL
MSVCRT__get_printf_count_output( void )
50 return n_format_enabled
? 1 : 0;
53 /*********************************************************************
54 * _set_printf_count_output (MSVCR80.@)
56 int CDECL
MSVCRT__set_printf_count_output( int enable
)
58 BOOL old
= n_format_enabled
;
59 n_format_enabled
= enable
!= 0;
63 #endif /* _MSVCR_VER>=80 */
65 /*********************************************************************
68 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsdup( const MSVCRT_wchar_t
* str
)
70 MSVCRT_wchar_t
* ret
= NULL
;
73 int size
= (strlenW(str
) + 1) * sizeof(MSVCRT_wchar_t
);
74 ret
= MSVCRT_malloc( size
);
75 if (ret
) memcpy( ret
, str
, size
);
80 INT CDECL
MSVCRT__wcsicmp_l(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, MSVCRT__locale_t locale
)
82 if(!MSVCRT_CHECK_PMT(str1
!= NULL
) || !MSVCRT_CHECK_PMT(str2
!= NULL
))
83 return MSVCRT__NLSCMPERROR
;
85 return strcmpiW(str1
, str2
);
88 /*********************************************************************
91 INT CDECL
MSVCRT__wcsicmp( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
93 return strcmpiW( str1
, str2
);
96 /*********************************************************************
97 * _wcsnicmp_l (MSVCRT.@)
99 INT CDECL
MSVCRT__wcsnicmp_l(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
, MSVCRT__locale_t locale
)
101 return strncmpiW(str1
, str2
, n
);
104 /*********************************************************************
105 * _wcsnicmp (MSVCRT.@)
107 INT CDECL
MSVCRT__wcsnicmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
)
109 return MSVCRT__wcsnicmp_l(str1
, str2
, n
, NULL
);
112 /*********************************************************************
113 * _wcsicoll_l (MSVCRT.@)
115 int CDECL
MSVCRT__wcsicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
117 MSVCRT_pthreadlocinfo locinfo
;
120 locinfo
= get_locinfo();
122 locinfo
= locale
->locinfo
;
124 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
125 return strcmpiW(str1
, str2
);
126 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
127 str1
, -1, str2
, -1)-CSTR_EQUAL
;
130 /*********************************************************************
131 * _wcsicoll (MSVCRT.@)
133 INT CDECL
MSVCRT__wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
135 return MSVCRT__wcsicoll_l(str1
, str2
, NULL
);
138 /*********************************************************************
139 * _wcsnicoll_l (MSVCRT.@)
141 int CDECL
MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
142 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
144 MSVCRT_pthreadlocinfo locinfo
;
147 locinfo
= get_locinfo();
149 locinfo
= locale
->locinfo
;
151 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
152 return strncmpiW(str1
, str2
, count
);
153 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
154 str1
, MSVCRT_wcsnlen(str1
, count
),
155 str2
, MSVCRT_wcsnlen(str2
, count
))-CSTR_EQUAL
;
158 /*********************************************************************
159 * _wcsnicoll (MSVCRT.@)
161 INT CDECL
MSVCRT__wcsnicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
163 return MSVCRT__wcsnicoll_l(str1
, str2
, count
, NULL
);
166 /*********************************************************************
167 * _wcsnset (MSVCRT.@)
169 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
171 MSVCRT_wchar_t
* ret
= str
;
172 while ((n
-- > 0) && *str
) *str
++ = c
;
176 /*********************************************************************
179 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsrev( MSVCRT_wchar_t
* str
)
181 MSVCRT_wchar_t
* ret
= str
;
182 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
185 MSVCRT_wchar_t t
= *end
;
192 /*********************************************************************
193 * _wcsset_s (MSVCRT.@)
195 int CDECL
MSVCRT__wcsset_s( MSVCRT_wchar_t
*str
, MSVCRT_size_t n
, MSVCRT_wchar_t c
)
197 MSVCRT_wchar_t
*p
= str
;
199 if(!MSVCRT_CHECK_PMT(str
!= NULL
)) return MSVCRT_EINVAL
;
200 if(!MSVCRT_CHECK_PMT(n
)) return MSVCRT_EINVAL
;
202 while(*p
&& --n
) *p
++ = c
;
205 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
206 *MSVCRT__errno() = MSVCRT_EINVAL
;
207 return MSVCRT_EINVAL
;
212 /*********************************************************************
215 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
217 MSVCRT_wchar_t
* ret
= str
;
218 while (*str
) *str
++ = c
;
222 /******************************************************************
223 * _wcsupr_s_l (MSVCRT.@)
225 int CDECL
MSVCRT__wcsupr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
,
226 MSVCRT__locale_t locale
)
228 MSVCRT_wchar_t
* ptr
= str
;
232 if (str
) *str
= '\0';
233 *MSVCRT__errno() = MSVCRT_EINVAL
;
234 return MSVCRT_EINVAL
;
240 /* FIXME: add locale support */
241 *ptr
= toupperW(*ptr
);
245 /* MSDN claims that the function should return and set errno to
246 * ERANGE, which doesn't seem to be true based on the tests. */
248 *MSVCRT__errno() = MSVCRT_EINVAL
;
249 return MSVCRT_EINVAL
;
252 /******************************************************************
253 * _wcsupr_s (MSVCRT.@)
256 INT CDECL
MSVCRT__wcsupr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
258 return MSVCRT__wcsupr_s_l( str
, n
, NULL
);
261 /******************************************************************
262 * _wcsupr_l (MSVCRT.@)
264 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsupr_l( MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
266 MSVCRT__wcsupr_s_l( str
, -1, locale
);
270 /******************************************************************
273 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsupr( MSVCRT_wchar_t
*str
)
275 return MSVCRT__wcsupr_l(str
, NULL
);
278 /******************************************************************
279 * _wcslwr_s_l (MSVCRT.@)
281 int CDECL
MSVCRT__wcslwr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
, MSVCRT__locale_t locale
)
283 MSVCRT_wchar_t
* ptr
= str
;
287 if (str
) *str
= '\0';
288 *MSVCRT__errno() = MSVCRT_EINVAL
;
289 return MSVCRT_EINVAL
;
295 *ptr
= tolowerW(*ptr
);
299 /* MSDN claims that the function should return and set errno to
300 * ERANGE, which doesn't seem to be true based on the tests. */
302 *MSVCRT__errno() = MSVCRT_EINVAL
;
303 return MSVCRT_EINVAL
;
306 /******************************************************************
307 * _wcslwr_s (MSVCRT.@)
309 int CDECL
MSVCRT__wcslwr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
311 return MSVCRT__wcslwr_s_l(str
, n
, NULL
);
314 /******************************************************************
315 * _wcslwr_l (MSVCRT.@)
317 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr_l( MSVCRT_wchar_t
* str
, MSVCRT__locale_t locale
)
319 MSVCRT__wcslwr_s_l(str
, -1, locale
);
323 /******************************************************************
326 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr( MSVCRT_wchar_t
* str
)
328 MSVCRT__wcslwr_s_l(str
, -1, NULL
);
332 /*********************************************************************
333 * _wcsncoll_l (MSVCRT.@)
335 int CDECL
MSVCRT__wcsncoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
336 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
338 MSVCRT_pthreadlocinfo locinfo
;
341 locinfo
= get_locinfo();
343 locinfo
= locale
->locinfo
;
345 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
346 return strncmpW(str1
, str2
, count
);
347 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0,
348 str1
, MSVCRT_wcsnlen(str1
, count
),
349 str2
, MSVCRT_wcsnlen(str2
, count
))-CSTR_EQUAL
;
352 /*********************************************************************
353 * _wcsncoll (MSVCRT.@)
355 int CDECL
MSVCRT__wcsncoll(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
357 return MSVCRT__wcsncoll_l(str1
, str2
, count
, NULL
);
360 /*********************************************************************
361 * _wcstod_l (MSVCRT.@)
363 double CDECL
MSVCRT__wcstod_l(const MSVCRT_wchar_t
* str
, MSVCRT_wchar_t
** end
,
364 MSVCRT__locale_t locale
)
366 MSVCRT_pthreadlocinfo locinfo
;
367 unsigned __int64 d
=0, hlp
;
370 const MSVCRT_wchar_t
*p
;
372 long double lret
=1, expcnt
= 10;
373 BOOL found_digit
= FALSE
, negexp
;
375 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
378 locinfo
= get_locinfo();
380 locinfo
= locale
->locinfo
;
392 while(*p
>='0' && *p
<='9') {
394 hlp
= d
*10+*(p
++)-'0';
395 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
401 while(*p
>='0' && *p
<='9') {
405 if(*p
== *locinfo
->lconv
->decimal_point
)
408 while(*p
>='0' && *p
<='9') {
410 hlp
= d
*10+*(p
++)-'0';
411 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
417 while(*p
>='0' && *p
<='9')
422 *end
= (MSVCRT_wchar_t
*)str
;
426 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
436 if(*p
>='0' && *p
<='9') {
437 while(*p
>='0' && *p
<='9') {
438 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
444 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
445 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
448 if(*p
=='-' || *p
=='+')
454 fpcontrol
= _control87(0, 0);
455 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
456 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
465 expcnt
= expcnt
*expcnt
;
467 ret
= (long double)sign
* (negexp
? d
/lret
: d
*lret
);
469 _control87(fpcontrol
, 0xffffffff);
471 if((d
&& ret
==0.0) || isinf(ret
))
472 *MSVCRT__errno() = MSVCRT_ERANGE
;
475 *end
= (MSVCRT_wchar_t
*)p
;
480 /*********************************************************************
481 * wcsrtombs_l (INTERNAL)
483 static MSVCRT_size_t
MSVCRT_wcsrtombs_l(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
484 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
486 MSVCRT_pthreadlocinfo locinfo
;
487 MSVCRT_size_t tmp
= 0;
491 locinfo
= get_locinfo();
493 locinfo
= locale
->locinfo
;
495 if(!locinfo
->lc_codepage
) {
499 return strlenW(*wcstr
);
501 for(i
=0; i
<count
; i
++) {
502 if((*wcstr
)[i
] > 255) {
503 *MSVCRT__errno() = MSVCRT_EILSEQ
;
507 mbstr
[i
] = (*wcstr
)[i
];
508 if(!(*wcstr
)[i
]) break;
514 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
515 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
516 if(!tmp
|| used_default
) {
517 *MSVCRT__errno() = MSVCRT_EILSEQ
;
525 MSVCRT_size_t i
, size
;
527 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
528 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
529 if(!size
|| used_default
) {
530 *MSVCRT__errno() = MSVCRT_EILSEQ
;
536 for(i
=0; i
<size
; i
++)
537 mbstr
[tmp
++] = buf
[i
];
548 /*********************************************************************
549 * _wcstombs_l (MSVCRT.@)
551 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
552 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
554 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
557 /*********************************************************************
558 * wcstombs (MSVCRT.@)
560 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
563 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
566 /*********************************************************************
567 * wcsrtombs (MSVCRT.@)
569 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
570 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
575 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
578 /*********************************************************************
579 * MSVCRT_wcsrtombs_s_l (INTERNAL)
581 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
582 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
583 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
587 if(!mbstr
&& !size
&& wcstr
) {
588 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
590 return *MSVCRT__errno();
596 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
597 if (size
) mbstr
[0] = '\0';
598 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
599 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
601 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
606 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
610 return *MSVCRT__errno();
611 }else if(conv
< size
)
612 mbstr
[conv
++] = '\0';
613 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
614 mbstr
[conv
-1] = '\0';
616 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
619 return MSVCRT_ERANGE
;
627 /*********************************************************************
628 * _wcstombs_s_l (MSVCRT.@)
630 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
631 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
632 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
634 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
637 /*********************************************************************
638 * wcstombs_s (MSVCRT.@)
640 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
641 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
643 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
646 /*********************************************************************
647 * wcsrtombs_s (MSVCRT.@)
649 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
650 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
655 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
658 /*********************************************************************
661 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
663 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
666 /*********************************************************************
669 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
671 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
674 /*********************************************************************
677 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
679 return MSVCRT__wcstod_l(str
, NULL
, locale
);
684 /*********************************************************************
685 * _wcstof_l (MSVCR120.@)
687 float CDECL
MSVCRT__wcstof_l( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
, MSVCRT__locale_t locale
)
689 return MSVCRT__wcstod_l(str
, end
, locale
);
692 /*********************************************************************
693 * wcstof (MSVCR120.@)
695 float CDECL
MSVCRT_wcstof( const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t
**end
)
697 return MSVCRT__wcstof_l(str
, end
, NULL
);
700 #endif /* _MSVCR_VER>=120 */
702 /*********************************************************************
703 * arg_clbk_valist (INTERNAL)
705 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
710 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
711 else if(type
== VT_INT
)
712 ret
.get_int
= va_arg(*valist
, int);
713 else if(type
== VT_R8
)
714 ret
.get_double
= va_arg(*valist
, double);
715 else if(type
== VT_PTR
)
716 ret
.get_ptr
= va_arg(*valist
, void*);
718 ERR("Incorrect type\n");
725 /*********************************************************************
726 * arg_clbk_positional (INTERNAL)
728 printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
730 printf_arg
*args
= ctx
;
734 /*********************************************************************
735 * _vsnprintf (MSVCRT.@)
737 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
738 const char *format
, __ms_va_list valist
)
740 static const char nullbyte
= '\0';
741 struct _str_ctx_a ctx
= {len
, str
};
744 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, 0,
745 arg_clbk_valist
, NULL
, &valist
);
746 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
752 static int puts_clbk_str_c99_a(void *ctx
, int len
, const char *str
)
754 struct _str_ctx_a
*out
= ctx
;
760 memcpy(out
->buf
, str
, out
->len
);
761 out
->buf
+= out
->len
;
766 memcpy(out
->buf
, str
, len
);
772 /*********************************************************************
773 * __stdio_common_vsprintf (UCRTBASE.@)
775 int CDECL
MSVCRT__stdio_common_vsprintf( unsigned __int64 options
, char *str
, MSVCRT_size_t len
, const char *format
,
776 MSVCRT__locale_t locale
, __ms_va_list valist
)
778 static const char nullbyte
= '\0';
779 struct _str_ctx_a ctx
= {len
, str
};
782 if (options
& ~UCRTBASE_PRINTF_MASK
)
783 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
784 ret
= pf_printf_a(puts_clbk_str_c99_a
,
785 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
786 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
790 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
791 return ret
>len
? -1 : ret
;
793 if(len
) str
[len
-1] = 0;
794 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
799 #endif /* _MSVCR_VER>=140 */
801 /*********************************************************************
802 * _vsnprintf_l (MSVCRT.@)
804 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
805 MSVCRT__locale_t locale
, __ms_va_list valist
)
807 static const char nullbyte
= '\0';
808 struct _str_ctx_a ctx
= {len
, str
};
811 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, 0,
812 arg_clbk_valist
, NULL
, &valist
);
813 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
817 /*********************************************************************
818 * _vsprintf_l (MSVCRT.@)
820 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
821 MSVCRT__locale_t locale
, __ms_va_list valist
)
823 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
826 /*********************************************************************
827 * _sprintf_l (MSVCRT.@)
829 int WINAPIV
MSVCRT_sprintf_l(char *str
, const char *format
,
830 MSVCRT__locale_t locale
, ...)
834 __ms_va_start(valist
, locale
);
835 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
840 static int CDECL
MSVCRT_vsnprintf_s_l_opt( char *str
, MSVCRT_size_t sizeOfBuffer
,
841 MSVCRT_size_t count
, const char *format
, DWORD options
,
842 MSVCRT__locale_t locale
, __ms_va_list valist
)
844 static const char nullbyte
= '\0';
845 struct _str_ctx_a ctx
;
848 if(sizeOfBuffer
<count
+1 || count
==-1)
855 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
856 arg_clbk_valist
, NULL
, &valist
);
857 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
859 if(ret
<0 || ret
==len
) {
860 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
861 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
862 memset(str
, 0, sizeOfBuffer
);
872 static int MSVCRT_vsnwprintf_s_l_opt( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
873 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, DWORD options
,
874 MSVCRT__locale_t locale
, __ms_va_list valist
)
876 static const MSVCRT_wchar_t nullbyte
= '\0';
877 struct _str_ctx_w ctx
;
881 if(count
!=-1 && len
>count
+1)
886 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
887 arg_clbk_valist
, NULL
, &valist
);
888 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
890 if(ret
<0 || ret
==len
) {
891 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
892 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
893 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
903 /*********************************************************************
904 * _vsnprintf_s_l (MSVCRT.@)
906 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
907 MSVCRT_size_t count
, const char *format
,
908 MSVCRT__locale_t locale
, __ms_va_list valist
)
910 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
913 /*********************************************************************
914 * _vsprintf_s_l (MSVCRT.@)
916 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
917 MSVCRT__locale_t locale
, __ms_va_list valist
)
919 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
922 /*********************************************************************
923 * _sprintf_s_l (MSVCRT.@)
925 int WINAPIV
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
926 MSVCRT__locale_t locale
, ...)
930 __ms_va_start(valist
, locale
);
931 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
936 /*********************************************************************
937 * _vsnprintf_s (MSVCRT.@)
939 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
940 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
942 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
947 /*********************************************************************
948 * __stdio_common_vsnprintf_s (UCRTBASE.@)
950 int CDECL
MSVCRT__stdio_common_vsnprintf_s( unsigned __int64 options
,
951 char *str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
952 const char *format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
954 if (options
& ~UCRTBASE_PRINTF_MASK
)
955 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
956 return MSVCRT_vsnprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
959 /*********************************************************************
960 * __stdio_common_vsnwprintf_s (UCRTBASE.@)
962 int CDECL
MSVCRT__stdio_common_vsnwprintf_s( unsigned __int64 options
,
963 MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
, MSVCRT_size_t count
,
964 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list valist
)
966 if (options
& ~UCRTBASE_PRINTF_MASK
)
967 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
968 return MSVCRT_vsnwprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
971 /*********************************************************************
972 * __stdio_common_vswprintf_s (UCRTBASE.@)
974 int CDECL
MSVCRT__stdio_common_vswprintf_s( unsigned __int64 options
,
975 MSVCRT_wchar_t
*str
, MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
976 MSVCRT__locale_t locale
, __ms_va_list valist
)
978 return MSVCRT__stdio_common_vsnwprintf_s(options
, str
, INT_MAX
, count
, format
, locale
, valist
);
981 /*********************************************************************
982 * __stdio_common_vsprintf_s (UCRTBASE.@)
984 int CDECL
MSVCRT__stdio_common_vsprintf_s( unsigned __int64 options
,
985 char *str
, MSVCRT_size_t count
, const char *format
,
986 MSVCRT__locale_t locale
, __ms_va_list valist
)
988 if (options
& ~UCRTBASE_PRINTF_MASK
)
989 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
990 return MSVCRT_vsnprintf_s_l_opt(str
, INT_MAX
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
993 #endif /* _MSVCR_VER>=140 */
995 /*********************************************************************
996 * vsprintf (MSVCRT.@)
998 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
1000 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
1003 /*********************************************************************
1004 * vsprintf_s (MSVCRT.@)
1006 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
1008 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
1011 /*********************************************************************
1012 * _vscprintf (MSVCRT.@)
1014 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
1016 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
1019 /*********************************************************************
1020 * _vscprintf_l (MSVCRT.@)
1022 int CDECL
MSVCRT__vscprintf_l(const char *format
,
1023 MSVCRT__locale_t locale
, __ms_va_list valist
)
1025 return MSVCRT_vsnprintf_l(NULL
, INT_MAX
, format
, locale
, valist
);
1028 /*********************************************************************
1029 * _vscprintf_p_l (MSVCRT.@)
1031 int CDECL
MSVCRT__vscprintf_p_l(const char *format
,
1032 MSVCRT__locale_t locale
, __ms_va_list args
)
1034 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1035 struct _str_ctx_a puts_ctx
= {INT_MAX
, NULL
};
1038 memset(args_ctx
, 0, sizeof(args_ctx
));
1040 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1042 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1043 *MSVCRT__errno() = MSVCRT_EINVAL
;
1045 } else if(ret
== 0) {
1046 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1047 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1048 arg_clbk_valist
, NULL
, &args
);
1050 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1051 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
,
1052 arg_clbk_positional
, args_ctx
, NULL
);
1058 /*********************************************************************
1059 * _vscprintf_p (MSVCR80.@)
1061 int CDECL
MSVCRT__vscprintf_p(const char *format
, __ms_va_list argptr
)
1063 return MSVCRT__vscprintf_p_l(format
, NULL
, argptr
);
1066 /*********************************************************************
1067 * _snprintf (MSVCRT.@)
1069 int WINAPIV
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
1072 __ms_va_list valist
;
1073 __ms_va_start(valist
, format
);
1074 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
1075 __ms_va_end(valist
);
1079 /*********************************************************************
1080 * _snprintf_l (MSVCRT.@)
1082 int WINAPIV
MSVCRT__snprintf_l(char *str
, unsigned int count
, MSVCRT__locale_t locale
,
1083 const char *format
, ...)
1086 __ms_va_list valist
;
1087 __ms_va_start(valist
, format
);
1088 retval
= MSVCRT_vsnprintf_l(str
, count
, format
, locale
, valist
);
1089 __ms_va_end(valist
);
1093 /*********************************************************************
1094 * _snprintf_s (MSVCRT.@)
1096 int WINAPIV
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
1097 const char *format
, ...)
1100 __ms_va_list valist
;
1101 __ms_va_start(valist
, format
);
1102 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1103 __ms_va_end(valist
);
1107 /*********************************************************************
1108 * _scprintf (MSVCRT.@)
1110 int WINAPIV
MSVCRT__scprintf(const char *format
, ...)
1113 __ms_va_list valist
;
1114 __ms_va_start(valist
, format
);
1115 retval
= MSVCRT__vscprintf(format
, valist
);
1116 __ms_va_end(valist
);
1120 /*********************************************************************
1121 * _vsnwprintf (MSVCRT.@)
1123 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1124 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1126 static const MSVCRT_wchar_t nullbyte
= '\0';
1127 struct _str_ctx_w ctx
= {len
, str
};
1130 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, 0,
1131 arg_clbk_valist
, NULL
, &valist
);
1132 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1136 /*********************************************************************
1137 * _vsnwprintf_l (MSVCRT.@)
1139 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
1140 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
1141 __ms_va_list valist
)
1143 static const MSVCRT_wchar_t nullbyte
= '\0';
1144 struct _str_ctx_w ctx
= {len
, str
};
1147 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, 0,
1148 arg_clbk_valist
, NULL
, &valist
);
1149 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1153 static int MSVCRT_vswprintf_p_l_opt(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1154 const MSVCRT_wchar_t
*format
, DWORD options
, MSVCRT__locale_t locale
, __ms_va_list args
)
1156 static const MSVCRT_wchar_t nullbyte
= '\0';
1157 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1158 struct _str_ctx_w puts_ctx
= {length
, buffer
};
1161 memset(args_ctx
, 0, sizeof(args_ctx
));
1163 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
1165 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1166 *MSVCRT__errno() = MSVCRT_EINVAL
;
1169 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1170 arg_clbk_valist
, NULL
, &args
);
1172 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
,
1173 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1174 arg_clbk_positional
, args_ctx
, NULL
);
1176 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
1180 /*********************************************************************
1181 * _vswprintf_p_l (MSVCRT.@)
1183 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1184 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1186 return MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, locale
, args
);
1190 /*********************************************************************
1191 * _vswprintf_p (MSVCR80.@)
1193 int CDECL
MSVCRT__vswprintf_p(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1194 const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1196 return MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, NULL
, args
);
1201 /*********************************************************************
1202 * __stdio_common_vswprintf_p (UCRTBASE.@)
1204 int CDECL
MSVCRT__stdio_common_vswprintf_p( unsigned __int64 options
,
1205 MSVCRT_wchar_t
*str
, MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1206 MSVCRT__locale_t locale
, __ms_va_list valist
)
1208 if (options
& ~UCRTBASE_PRINTF_MASK
)
1209 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1210 return MSVCRT_vswprintf_p_l_opt(str
, count
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, valist
);
1214 /*********************************************************************
1215 * _vsnwprintf_s_l (MSVCRT.@)
1217 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1218 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
1219 MSVCRT__locale_t locale
, __ms_va_list valist
)
1221 return MSVCRT_vsnwprintf_s_l_opt(str
, sizeOfBuffer
, count
, format
, 0, locale
, valist
);
1224 /*********************************************************************
1225 * _vsnwprintf_s (MSVCRT.@)
1227 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
1228 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
1230 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
1231 format
, NULL
, valist
);
1234 /*********************************************************************
1235 * _snwprintf (MSVCRT.@)
1237 int WINAPIV
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
1240 __ms_va_list valist
;
1241 __ms_va_start(valist
, format
);
1242 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
1243 __ms_va_end(valist
);
1247 /*********************************************************************
1248 * _snwprintf_l (MSVCRT.@)
1250 int WINAPIV
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
1251 MSVCRT__locale_t locale
, ...)
1254 __ms_va_list valist
;
1255 __ms_va_start(valist
, locale
);
1256 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
1257 __ms_va_end(valist
);
1261 /*********************************************************************
1262 * _snwprintf_s (MSVCRT.@)
1264 int WINAPIV
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1265 const MSVCRT_wchar_t
*format
, ...)
1268 __ms_va_list valist
;
1269 __ms_va_start(valist
, format
);
1270 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
1271 __ms_va_end(valist
);
1275 /*********************************************************************
1276 * _snwprintf_s_l (MSVCRT.@)
1278 int WINAPIV
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
1279 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1282 __ms_va_list valist
;
1283 __ms_va_start(valist
, locale
);
1284 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
1285 __ms_va_end(valist
);
1291 static int puts_clbk_str_c99_w(void *ctx
, int len
, const MSVCRT_wchar_t
*str
)
1293 struct _str_ctx_w
*out
= ctx
;
1298 if(out
->len
< len
) {
1299 memcpy(out
->buf
, str
, out
->len
*sizeof(MSVCRT_wchar_t
));
1300 out
->buf
+= out
->len
;
1305 memcpy(out
->buf
, str
, len
*sizeof(MSVCRT_wchar_t
));
1311 /*********************************************************************
1312 * __stdio_common_vswprintf (UCRTBASE.@)
1314 int CDECL
MSVCRT__stdio_common_vswprintf( unsigned __int64 options
,
1315 MSVCRT_wchar_t
*str
, MSVCRT_size_t len
, const MSVCRT_wchar_t
*format
,
1316 MSVCRT__locale_t locale
, __ms_va_list valist
)
1318 static const MSVCRT_wchar_t nullbyte
= '\0';
1319 struct _str_ctx_w ctx
= {len
, str
};
1322 if (options
& ~UCRTBASE_PRINTF_MASK
)
1323 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1324 ret
= pf_printf_w(puts_clbk_str_c99_w
,
1325 &ctx
, format
, locale
, options
& UCRTBASE_PRINTF_MASK
, arg_clbk_valist
, NULL
, &valist
);
1326 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
1330 if(options
& UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION
)
1331 return ret
>len
? -1 : ret
;
1333 if(len
) str
[len
-1] = 0;
1334 return (options
& UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
) ? ret
: -2;
1339 #endif /* _MSVCR_VER>=140 */
1341 /*********************************************************************
1342 * sprintf (MSVCRT.@)
1344 int WINAPIV
MSVCRT_sprintf( char *str
, const char *format
, ... )
1349 __ms_va_start( ap
, format
);
1350 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
1355 /*********************************************************************
1356 * sprintf_s (MSVCRT.@)
1358 int WINAPIV
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
1363 __ms_va_start( ap
, format
);
1364 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
1369 /*********************************************************************
1370 * _scwprintf (MSVCRT.@)
1372 int WINAPIV
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
1377 __ms_va_start( ap
, format
);
1378 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1383 /*********************************************************************
1384 * swprintf (MSVCRT.@)
1386 int WINAPIV
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1391 __ms_va_start( ap
, format
);
1392 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1397 /*********************************************************************
1398 * swprintf_s (MSVCRT.@)
1400 int WINAPIV
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1401 const MSVCRT_wchar_t
*format
, ... )
1406 __ms_va_start(ap
, format
);
1407 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1413 /*********************************************************************
1414 * _swprintf_s_l (MSVCRT.@)
1416 int WINAPIV
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1417 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1422 __ms_va_start(ap
, locale
);
1423 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1429 /*********************************************************************
1430 * _vswprintf (MSVCRT.@)
1432 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1434 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1437 /*********************************************************************
1438 * _vswprintf (MSVCRT.@)
1440 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1441 MSVCRT__locale_t locale
, __ms_va_list args
)
1443 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1446 /*********************************************************************
1447 * _vscwprintf (MSVCRT.@)
1449 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1451 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1454 /*********************************************************************
1455 * _vscwprintf_l (MSVCRT.@)
1457 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1459 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1462 /*********************************************************************
1463 * _vscwprintf_p_l (MSVCRT.@)
1465 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1467 return MSVCRT_vswprintf_p_l_opt( NULL
, INT_MAX
, format
, 0, locale
, args
);
1471 /*********************************************************************
1472 * _vscwprintf_p (MSVCR80.@)
1474 int CDECL
MSVCRT__vscwprintf_p(const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1476 return MSVCRT_vswprintf_p_l_opt(NULL
, INT_MAX
, format
, 0, NULL
, args
);
1480 /*********************************************************************
1481 * vswprintf_s (MSVCRT.@)
1483 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1484 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1486 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1489 /*********************************************************************
1490 * _vswprintf_s_l (MSVCRT.@)
1492 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1493 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1495 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1496 format
, locale
, args
);
1499 static int MSVCRT_vsprintf_p_l_opt(char *buffer
, MSVCRT_size_t length
, const char *format
,
1500 DWORD options
, MSVCRT__locale_t locale
, __ms_va_list args
)
1502 static const char nullbyte
= '\0';
1503 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1504 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1507 memset(args_ctx
, 0, sizeof(args_ctx
));
1509 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1511 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1512 *MSVCRT__errno() = MSVCRT_EINVAL
;
1515 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1516 MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
, arg_clbk_valist
, NULL
, &args
);
1518 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
,
1519 MSVCRT_PRINTF_POSITIONAL_PARAMS
| MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
| options
,
1520 arg_clbk_positional
, args_ctx
, NULL
);
1522 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1526 /*********************************************************************
1527 * _vsprintf_p_l (MSVCRT.@)
1529 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1530 MSVCRT__locale_t locale
, __ms_va_list args
)
1532 return MSVCRT_vsprintf_p_l_opt(buffer
, length
, format
, 0, locale
, args
);
1535 /*********************************************************************
1536 * _vsprintf_p (MSVCRT.@)
1538 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1539 const char *format
, __ms_va_list args
)
1541 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1545 /*********************************************************************
1546 * __stdio_common_vsprintf_p (UCRTBASE.@)
1548 int CDECL
MSVCRT__stdio_common_vsprintf_p(unsigned __int64 options
, char *buffer
, MSVCRT_size_t length
,
1549 const char *format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1551 if (options
& ~UCRTBASE_PRINTF_MASK
)
1552 FIXME("options %s not handled\n", wine_dbgstr_longlong(options
));
1553 return MSVCRT_vsprintf_p_l_opt(buffer
, length
, format
, options
& UCRTBASE_PRINTF_MASK
, locale
, args
);
1557 /*********************************************************************
1558 * _sprintf_p_l (MSVCRT.@)
1560 int WINAPIV
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1561 const char *format
, MSVCRT__locale_t locale
, ...)
1563 __ms_va_list valist
;
1566 __ms_va_start(valist
, locale
);
1567 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1568 __ms_va_end(valist
);
1573 /*********************************************************************
1574 * __swprintf_l (MSVCRT.@)
1576 int WINAPIV
MSVCRT___swprintf_l( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
,
1577 MSVCRT__locale_t locale
, ...)
1580 __ms_va_list valist
;
1581 __ms_va_start(valist
, locale
);
1582 retval
= MSVCRT_vswprintf_l(str
, format
, locale
, valist
);
1583 __ms_va_end(valist
);
1588 /*********************************************************************
1589 * _sprintf_p (MSVCR80.@)
1591 int WINAPIV
MSVCRT__sprintf_p(char *buffer
, MSVCRT_size_t length
, const char *format
, ...)
1593 __ms_va_list valist
;
1596 __ms_va_start(valist
, format
);
1597 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, valist
);
1598 __ms_va_end(valist
);
1604 /*********************************************************************
1605 * _swprintf_p_l (MSVCRT.@)
1607 int WINAPIV
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1608 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1610 __ms_va_list valist
;
1613 __ms_va_start(valist
, locale
);
1614 r
= MSVCRT_vswprintf_p_l_opt(buffer
, length
, format
, 0, locale
, valist
);
1615 __ms_va_end(valist
);
1620 /*********************************************************************
1621 * _wcscoll_l (MSVCRT.@)
1623 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1625 MSVCRT_pthreadlocinfo locinfo
;
1628 locinfo
= get_locinfo();
1630 locinfo
= locale
->locinfo
;
1632 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1633 return strcmpW(str1
, str2
);
1634 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1637 /*********************************************************************
1638 * wcscoll (MSVCRT.@)
1640 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1642 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1645 /*********************************************************************
1646 * wcspbrk (MSVCRT.@)
1648 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1650 const MSVCRT_wchar_t
* p
;
1654 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1660 /*********************************************************************
1661 * wcstok_s (MSVCRT.@)
1663 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1664 MSVCRT_wchar_t
**next_token
)
1666 MSVCRT_wchar_t
*ret
;
1668 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1669 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1670 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1672 if (!str
) str
= *next_token
;
1674 while (*str
&& strchrW( delim
, *str
)) str
++;
1675 if (!*str
) return NULL
;
1677 while (*str
&& !strchrW( delim
, *str
)) str
++;
1678 if (*str
) *str
++ = 0;
1683 /*********************************************************************
1686 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1688 return MSVCRT_wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1691 /*********************************************************************
1692 * _wctomb_s_l (MSVCRT.@)
1694 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1695 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1697 MSVCRT_pthreadlocinfo locinfo
;
1701 if(!mbchar
&& size
>0) {
1710 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1711 return MSVCRT_EINVAL
;
1714 locinfo
= get_locinfo();
1716 locinfo
= locale
->locinfo
;
1718 if(!locinfo
->lc_codepage
) {
1720 if(mbchar
&& size
>0)
1721 memset(mbchar
, 0, size
);
1722 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1723 return MSVCRT_EILSEQ
;
1726 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1727 return MSVCRT_ERANGE
;
1735 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1736 if(!mblen
|| error
) {
1737 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1738 if(mbchar
&& size
>0)
1739 memset(mbchar
, 0, size
);
1741 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1742 return MSVCRT_ERANGE
;
1745 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1746 return MSVCRT_EILSEQ
;
1754 /*********************************************************************
1755 * wctomb_s (MSVCRT.@)
1757 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1759 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1762 /*********************************************************************
1763 * _wctomb_l (MSVCRT.@)
1765 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1769 MSVCRT__wctomb_s_l(&len
, dst
, dst
? MSVCRT_MB_LEN_MAX
: 0, ch
, locale
);
1773 /*********************************************************************
1776 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1778 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1781 /*********************************************************************
1784 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1788 UINT codepage
= get_locinfo()->lc_codepage
;
1792 return (signed char)wchar
;
1795 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1800 /*********************************************************************
1801 * wcrtomb (MSVCRT.@)
1803 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1807 return MSVCRT_wctomb(dst
, ch
);
1810 /*********************************************************************
1811 * iswalnum (MSVCRT.@)
1813 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1815 return isalnumW( wc
);
1818 /*********************************************************************
1819 * _iswalnum_l (MSVCRT.@)
1821 int CDECL
MSVCRT__iswalnum_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1823 return isalnumW( wc
);
1826 /*********************************************************************
1827 * iswalpha (MSVCRT.@)
1829 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1831 return isalphaW( wc
);
1834 /*********************************************************************
1835 * iswalpha_l (MSVCRT.@)
1837 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1839 return isalphaW( wc
);
1842 /*********************************************************************
1843 * iswcntrl (MSVCRT.@)
1845 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1847 return iscntrlW( wc
);
1850 /*********************************************************************
1851 * _iswcntrl_l (MSVCRT.@)
1853 int CDECL
MSVCRT__iswcntrl_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1855 return iscntrlW( wc
);
1858 /*********************************************************************
1859 * iswdigit (MSVCRT.@)
1861 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1863 return isdigitW( wc
);
1866 /*********************************************************************
1867 * _iswdigit_l (MSVCRT.@)
1869 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1871 return isdigitW( wc
);
1874 /*********************************************************************
1875 * iswgraph (MSVCRT.@)
1877 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1879 return isgraphW( wc
);
1882 /*********************************************************************
1883 * _iswgraph_l (MSVCRT.@)
1885 int CDECL
MSVCRT__iswgraph_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1887 return isgraphW( wc
);
1890 /*********************************************************************
1891 * iswlower (MSVCRT.@)
1893 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1895 return islowerW( wc
);
1898 /*********************************************************************
1899 * _iswlower_l (MSVCRT.@)
1901 int CDECL
MSVCRT__iswlower_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1903 return islowerW( wc
);
1906 /*********************************************************************
1907 * iswprint (MSVCRT.@)
1909 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1911 return isprintW( wc
);
1914 /*********************************************************************
1915 * _iswprint_l (MSVCRT.@)
1917 int CDECL
MSVCRT__iswprint_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1919 return isprintW( wc
);
1922 /*********************************************************************
1923 * _iswpunct_l (MSVCRT.@)
1925 INT CDECL
MSVCRT__iswpunct_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1927 return ispunctW( wc
);
1930 /*********************************************************************
1931 * iswpunct (MSVCRT.@)
1933 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1935 return ispunctW( wc
);
1938 /*********************************************************************
1939 * _iswspace_l (MSVCRT.@)
1941 INT CDECL
MSVCRT__iswspace_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1943 return isspaceW( wc
);
1946 /*********************************************************************
1947 * iswspace (MSVCRT.@)
1949 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1951 return isspaceW( wc
);
1954 /*********************************************************************
1955 * iswupper (MSVCRT.@)
1957 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1959 return isupperW( wc
);
1962 /*********************************************************************
1963 * _iswupper_l (MSVCRT.@)
1965 int CDECL
MSVCRT__iswupper_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1967 return isupperW( wc
);
1970 /*********************************************************************
1971 * iswxdigit (MSVCRT.@)
1973 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1975 return isxdigitW( wc
);
1978 /*********************************************************************
1979 * _iswxdigit_l (MSVCRT.@)
1981 int CDECL
MSVCRT__iswxdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1983 return isxdigitW( wc
);
1986 /*********************************************************************
1987 * _iswctype_l (MSVCRT.@)
1989 INT CDECL
MSVCRT__iswctype_l( MSVCRT_wchar_t wc
, MSVCRT_wctype_t type
, MSVCRT__locale_t locale
)
1991 return (get_char_typeW(wc
) & 0xffff) & type
;
1994 /*********************************************************************
1995 * _iswblank_l (MSVCRT.@)
1997 INT CDECL
MSVCRT__iswblank_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1999 return wc
== '\t' || MSVCRT__iswctype_l( wc
, MSVCRT__BLANK
, locale
);
2002 /*********************************************************************
2003 * iswblank (MSVCRT.@)
2005 INT CDECL
MSVCRT_iswblank( MSVCRT_wchar_t wc
)
2007 return wc
== '\t' || MSVCRT__iswctype_l( wc
, MSVCRT__BLANK
, NULL
);
2010 /*********************************************************************
2011 * wcscpy_s (MSVCRT.@)
2013 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
2015 MSVCRT_size_t size
= 0;
2017 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
2018 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
2022 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
2024 size
= strlenW(wcSrc
) + 1;
2026 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
2027 return MSVCRT_ERANGE
;
2029 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
2034 /******************************************************************
2035 * wcsncpy (MSVCRT.@)
2037 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
2038 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
2043 if(!(s1
[i
] = s2
[i
])) break;
2049 /******************************************************************
2050 * wcsncpy_s (MSVCRT.@)
2052 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
2053 MSVCRT_size_t count
)
2056 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
2058 if(!wcDest
&& !numElement
&& !count
)
2061 if (!wcDest
|| !numElement
)
2062 return MSVCRT_EINVAL
;
2067 return count
? MSVCRT_EINVAL
: 0;
2070 while (numElement
&& count
&& *wcSrc
)
2076 if (!numElement
&& truncate
)
2079 return MSVCRT_STRUNCATE
;
2081 else if (!numElement
)
2084 return MSVCRT_ERANGE
;
2091 /******************************************************************
2092 * wcscat_s (MSVCRT.@)
2095 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
2097 MSVCRT_wchar_t
* ptr
= dst
;
2099 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
2103 return MSVCRT_EINVAL
;
2106 /* seek to end of dst string (or elem if no end of string is found */
2107 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
2108 while (ptr
< dst
+ elem
)
2110 if ((*ptr
++ = *src
++) == '\0') return 0;
2112 /* not enough space */
2114 return MSVCRT_ERANGE
;
2117 /*********************************************************************
2118 * wcsncat_s (MSVCRT.@)
2121 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
2122 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
2124 MSVCRT_size_t srclen
;
2125 MSVCRT_wchar_t dststart
;
2128 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
2129 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
2130 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
2135 for (dststart
= 0; dststart
< elem
; dststart
++)
2137 if (dst
[dststart
] == '\0')
2140 if (dststart
== elem
)
2142 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
2143 return MSVCRT_EINVAL
;
2146 if (count
== MSVCRT__TRUNCATE
)
2148 srclen
= strlenW(src
);
2149 if (srclen
>= (elem
- dststart
))
2151 srclen
= elem
- dststart
- 1;
2152 ret
= MSVCRT_STRUNCATE
;
2156 srclen
= min(strlenW(src
), count
);
2157 if (srclen
< (elem
- dststart
))
2159 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
2160 dst
[dststart
+srclen
] = '\0';
2163 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
2165 return MSVCRT_ERANGE
;
2168 /*********************************************************************
2169 * wctoint (INTERNAL)
2171 static int wctoint(WCHAR c
, int base
)
2174 if ('0' <= c
&& c
<= '9')
2176 else if ('A' <= c
&& c
<= 'Z')
2178 else if ('a' <= c
&& c
<= 'z')
2181 /* NOTE: wine_fold_string(MAP_FOLDDIGITS) supports too many things. */
2182 /* Unicode points that contain digits 0-9; keep this sorted! */
2183 static const WCHAR zeros
[] = {
2184 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
2185 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
2188 for (i
= 0; i
< ARRAY_SIZE(zeros
) && c
>= zeros
[i
]; ++i
) {
2189 if (zeros
[i
] <= c
&& c
<= zeros
[i
] + 9) {
2195 return v
< base
? v
: -1;
2198 /*********************************************************************
2199 * _wcstoi64_l (MSVCRT.@)
2201 * FIXME: locale parameter is ignored
2203 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
2204 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2206 BOOL negative
= FALSE
, empty
= TRUE
;
2209 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2211 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2212 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2213 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2216 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2218 while(isspaceW(*nptr
)) nptr
++;
2223 } else if(*nptr
== '+')
2226 if((base
==0 || base
==16) && wctoint(*nptr
, 1)==0 && tolowerW(*(nptr
+1))=='x') {
2232 if(wctoint(*nptr
, 1)==0)
2239 int v
= wctoint(*nptr
, base
);
2249 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
2250 ret
= MSVCRT_I64_MAX
;
2251 *MSVCRT__errno() = MSVCRT_ERANGE
;
2252 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
2253 ret
= MSVCRT_I64_MIN
;
2254 *MSVCRT__errno() = MSVCRT_ERANGE
;
2259 if(endptr
&& !empty
)
2260 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2265 /*********************************************************************
2266 * _wcstoi64 (MSVCRT.@)
2268 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
2269 MSVCRT_wchar_t
**endptr
, int base
)
2271 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
2274 /*********************************************************************
2275 * _wcstol_l (MSVCRT.@)
2277 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
2278 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2280 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
2282 if(ret
> MSVCRT_LONG_MAX
) {
2283 ret
= MSVCRT_LONG_MAX
;
2284 *MSVCRT__errno() = MSVCRT_ERANGE
;
2285 }else if(ret
< MSVCRT_LONG_MIN
) {
2286 ret
= MSVCRT_LONG_MIN
;
2287 *MSVCRT__errno() = MSVCRT_ERANGE
;
2292 /*********************************************************************
2295 MSVCRT_long CDECL
MSVCRT_wcstol(const MSVCRT_wchar_t
*s
,
2296 MSVCRT_wchar_t
**end
, int base
)
2298 return MSVCRT__wcstol_l(s
, end
, base
, NULL
);
2301 /*********************************************************************
2302 * _wtoi_l (MSVCRT.@)
2304 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2306 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2310 *MSVCRT__errno() = MSVCRT_ERANGE
;
2311 } else if(ret
< INT_MIN
) {
2313 *MSVCRT__errno() = MSVCRT_ERANGE
;
2318 /*********************************************************************
2321 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
2323 return MSVCRT__wtoi_l(str
, NULL
);
2326 /*********************************************************************
2327 * _wtol_l (MSVCRT.@)
2329 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2331 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2333 if(ret
> MSVCRT_LONG_MAX
) {
2334 ret
= MSVCRT_LONG_MAX
;
2335 *MSVCRT__errno() = MSVCRT_ERANGE
;
2336 } else if(ret
< MSVCRT_LONG_MIN
) {
2337 ret
= MSVCRT_LONG_MIN
;
2338 *MSVCRT__errno() = MSVCRT_ERANGE
;
2343 /*********************************************************************
2346 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
2348 return MSVCRT__wtol_l(str
, NULL
);
2353 /*********************************************************************
2354 * _wtoll_l (MSVCR120.@)
2356 MSVCRT_longlong __cdecl
MSVCRT__wtoll_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2358 return MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
2361 /*********************************************************************
2362 * _wtoll (MSVCR120.@)
2364 MSVCRT_longlong __cdecl
MSVCRT__wtoll(const MSVCRT_wchar_t
*str
)
2366 return MSVCRT__wtoll_l(str
, NULL
);
2369 #endif /* _MSVCR_VER>=120 */
2371 /*********************************************************************
2372 * _wcstoui64_l (MSVCRT.@)
2374 * FIXME: locale parameter is ignored
2376 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
2377 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
2379 BOOL negative
= FALSE
, empty
= TRUE
;
2380 unsigned __int64 ret
= 0;
2382 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
2384 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
2385 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
2386 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
2389 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2391 while(isspaceW(*nptr
)) nptr
++;
2396 } else if(*nptr
== '+')
2399 if((base
==0 || base
==16) && wctoint(*nptr
, 1)==0 && tolowerW(*(nptr
+1))=='x') {
2405 if(wctoint(*nptr
, 1)==0)
2412 int v
= wctoint(*nptr
, base
);
2419 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
2420 ret
= MSVCRT_UI64_MAX
;
2421 *MSVCRT__errno() = MSVCRT_ERANGE
;
2426 if(endptr
&& !empty
)
2427 *endptr
= (MSVCRT_wchar_t
*)nptr
;
2429 return negative
? -ret
: ret
;
2432 /*********************************************************************
2433 * _wcstoui64 (MSVCRT.@)
2435 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
2436 MSVCRT_wchar_t
**endptr
, int base
)
2438 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
2441 /*********************************************************************
2442 * _wcstoul_l (MSVCRT.@)
2444 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
2445 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
2447 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
2449 if(ret
> MSVCRT_ULONG_MAX
) {
2450 ret
= MSVCRT_ULONG_MAX
;
2451 *MSVCRT__errno() = MSVCRT_ERANGE
;
2456 /*********************************************************************
2457 * wcstoul (MSVCRT.@)
2459 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
2461 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
2464 /******************************************************************
2465 * wcsnlen (MSVCRT.@)
2467 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
2471 for (i
= 0; i
< maxlen
; i
++)
2476 /*********************************************************************
2477 * _towupper_l (MSVCRT.@)
2479 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2481 MSVCRT_pthreadlocinfo locinfo
;
2484 locinfo
= get_locinfo();
2486 locinfo
= locale
->locinfo
;
2488 if(!locinfo
->lc_handle
[MSVCRT_LC_CTYPE
]) {
2489 if(c
>= 'a' && c
<= 'z')
2490 return c
+ 'A' - 'a';
2497 /*********************************************************************
2498 * towupper (MSVCRT.@)
2500 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
2502 return MSVCRT__towupper_l(c
, NULL
);
2505 /*********************************************************************
2506 * _towlower_l (MSVCRT.@)
2508 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
2510 MSVCRT_pthreadlocinfo locinfo
;
2513 locinfo
= get_locinfo();
2515 locinfo
= locale
->locinfo
;
2517 if(!locinfo
->lc_handle
[MSVCRT_LC_CTYPE
]) {
2518 if(c
>= 'A' && c
<= 'Z')
2519 return c
+ 'a' - 'A';
2526 /*********************************************************************
2527 * towlower (MSVCRT.@)
2529 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
2531 return MSVCRT__towlower_l(c
, NULL
);
2534 /*********************************************************************
2537 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
2539 return strchrW(str
, ch
);
2542 /*********************************************************************
2543 * wcsrchr (MSVCRT.@)
2545 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsrchr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
2547 return strrchrW(str
, ch
);
2550 /***********************************************************************
2553 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
2555 return strlenW(str
);
2558 /*********************************************************************
2561 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
2563 return strstrW(str
, sub
);
2566 /*********************************************************************
2567 * _wtoi64_l (MSVCRT.@)
2569 __int64 CDECL
MSVCRT__wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2571 ULONGLONG RunningTotal
= 0;
2572 BOOL bMinus
= FALSE
;
2574 while (isspaceW(*str
)) {
2580 } else if (*str
== '-') {
2585 while (*str
>= '0' && *str
<= '9') {
2586 RunningTotal
= RunningTotal
* 10 + *str
- '0';
2590 return bMinus
? -RunningTotal
: RunningTotal
;
2593 /*********************************************************************
2594 * _wtoi64 (MSVCRT.@)
2596 __int64 CDECL
MSVCRT__wtoi64(const MSVCRT_wchar_t
*str
)
2598 return MSVCRT__wtoi64_l(str
, NULL
);
2601 /*********************************************************************
2602 * wcsncmp (MSVCRT.@)
2604 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
2606 return strncmpW(str1
, str2
, n
);
2609 /*********************************************************************
2610 * _wcsxfrm_l (MSVCRT.@)
2612 MSVCRT_size_t CDECL
MSVCRT__wcsxfrm_l(MSVCRT_wchar_t
*dest
, const MSVCRT_wchar_t
*src
,
2613 MSVCRT_size_t len
, MSVCRT__locale_t locale
)
2615 MSVCRT_pthreadlocinfo locinfo
;
2618 if(!MSVCRT_CHECK_PMT(src
)) return INT_MAX
;
2619 if(!MSVCRT_CHECK_PMT(dest
|| !len
)) return INT_MAX
;
2622 FIXME("len > INT_MAX not supported\n");
2627 locinfo
= get_locinfo();
2629 locinfo
= locale
->locinfo
;
2631 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]) {
2632 MSVCRT_wcsncpy(dest
, src
, len
);
2633 return strlenW(src
);
2636 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2637 LCMAP_SORTKEY
, src
, -1, NULL
, 0);
2639 if(len
) dest
[0] = 0;
2640 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2643 if(!len
) return ret
-1;
2647 *MSVCRT__errno() = MSVCRT_ERANGE
;
2651 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2652 LCMAP_SORTKEY
, src
, -1, dest
, len
) - 1;
2653 for(i
=ret
; i
>=0; i
--)
2654 dest
[i
] = ((unsigned char*)dest
)[i
];
2658 /*********************************************************************
2659 * wcsxfrm (MSVCRT.@)
2661 MSVCRT_size_t CDECL
MSVCRT_wcsxfrm(MSVCRT_wchar_t
*dest
,
2662 const MSVCRT_wchar_t
*src
, MSVCRT_size_t len
)
2664 return MSVCRT__wcsxfrm_l(dest
, src
, len
, NULL
);
2667 /*********************************************************************
2670 int CDECL
MSVCRT_wcscmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
)
2672 return strcmpW(str1
, str2
);