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 (MSVCRT.@)
95 INT CDECL
MSVCRT__wcsnicmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, INT n
)
97 return strncmpiW(str1
, str2
, n
);
100 /*********************************************************************
101 * _wcsicoll_l (MSVCRT.@)
103 int CDECL
MSVCRT__wcsicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
105 MSVCRT_pthreadlocinfo locinfo
;
108 locinfo
= get_locinfo();
110 locinfo
= locale
->locinfo
;
112 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
113 return strcmpiW(str1
, str2
);
114 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
115 str1
, -1, str2
, -1)-CSTR_EQUAL
;
118 /*********************************************************************
119 * _wcsicoll (MSVCRT.@)
121 INT CDECL
MSVCRT__wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
123 return MSVCRT__wcsicoll_l(str1
, str2
, NULL
);
126 /*********************************************************************
127 * _wcsnicoll_l (MSVCRT.@)
129 int CDECL
MSVCRT__wcsnicoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
130 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
132 MSVCRT_pthreadlocinfo locinfo
;
135 locinfo
= get_locinfo();
137 locinfo
= locale
->locinfo
;
139 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
140 return strncmpiW(str1
, str2
, count
);
141 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], NORM_IGNORECASE
,
142 str1
, count
, str2
, count
)-CSTR_EQUAL
;
145 /*********************************************************************
146 * _wcsnicoll (MSVCRT.@)
148 INT CDECL
MSVCRT__wcsnicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
150 return MSVCRT__wcsnicoll_l(str1
, str2
, count
, NULL
);
153 /*********************************************************************
154 * _wcsnset (MSVCRT.@)
156 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
158 MSVCRT_wchar_t
* ret
= str
;
159 while ((n
-- > 0) && *str
) *str
++ = c
;
163 /*********************************************************************
166 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsrev( MSVCRT_wchar_t
* str
)
168 MSVCRT_wchar_t
* ret
= str
;
169 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
172 MSVCRT_wchar_t t
= *end
;
179 /*********************************************************************
182 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
184 MSVCRT_wchar_t
* ret
= str
;
185 while (*str
) *str
++ = c
;
189 /******************************************************************
190 * _wcsupr_s_l (MSVCRT.@)
192 int CDECL
MSVCRT__wcsupr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
,
193 MSVCRT__locale_t locale
)
195 MSVCRT_wchar_t
* ptr
= str
;
199 if (str
) *str
= '\0';
200 *MSVCRT__errno() = MSVCRT_EINVAL
;
201 return MSVCRT_EINVAL
;
207 /* FIXME: add locale support */
208 *ptr
= toupperW(*ptr
);
212 /* MSDN claims that the function should return and set errno to
213 * ERANGE, which doesn't seem to be true based on the tests. */
215 *MSVCRT__errno() = MSVCRT_EINVAL
;
216 return MSVCRT_EINVAL
;
219 /******************************************************************
220 * _wcsupr_s (MSVCRT.@)
223 INT CDECL
MSVCRT__wcsupr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
225 return MSVCRT__wcsupr_s_l( str
, n
, NULL
);
228 /******************************************************************
229 * _wcsupr_l (MSVCRT.@)
231 MSVCRT_wchar_t
* CDECL
MSVCRT__wcsupr_l( MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
233 MSVCRT__wcsupr_s_l( str
, -1, locale
);
237 /******************************************************************
238 * _wcslwr_s_l (MSVCRT.@)
240 int CDECL
MSVCRT__wcslwr_s_l( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
, MSVCRT__locale_t locale
)
242 MSVCRT_wchar_t
* ptr
= str
;
246 if (str
) *str
= '\0';
247 *MSVCRT__errno() = MSVCRT_EINVAL
;
248 return MSVCRT_EINVAL
;
254 *ptr
= tolowerW(*ptr
);
258 /* MSDN claims that the function should return and set errno to
259 * ERANGE, which doesn't seem to be true based on the tests. */
261 *MSVCRT__errno() = MSVCRT_EINVAL
;
262 return MSVCRT_EINVAL
;
265 /******************************************************************
266 * _wcslwr_s (MSVCRT.@)
268 int CDECL
MSVCRT__wcslwr_s( MSVCRT_wchar_t
* str
, MSVCRT_size_t n
)
270 return MSVCRT__wcslwr_s_l(str
, n
, NULL
);
273 /******************************************************************
274 * _wcslwr_l (MSVCRT.@)
276 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr_l( MSVCRT_wchar_t
* str
, MSVCRT__locale_t locale
)
278 MSVCRT__wcslwr_s_l(str
, -1, locale
);
282 /******************************************************************
285 MSVCRT_wchar_t
* CDECL
MSVCRT__wcslwr( MSVCRT_wchar_t
* str
)
287 MSVCRT__wcslwr_s_l(str
, -1, NULL
);
291 /*********************************************************************
292 * _wcsncoll_l (MSVCRT.@)
294 int CDECL
MSVCRT__wcsncoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
,
295 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
297 MSVCRT_pthreadlocinfo locinfo
;
300 locinfo
= get_locinfo();
302 locinfo
= locale
->locinfo
;
304 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
305 return strncmpW(str1
, str2
, count
);
306 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, count
, str2
, count
)-CSTR_EQUAL
;
309 /*********************************************************************
310 * _wcsncoll (MSVCRT.@)
312 int CDECL
MSVCRT__wcsncoll(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT_size_t count
)
314 return MSVCRT__wcsncoll_l(str1
, str2
, count
, NULL
);
317 /*********************************************************************
318 * _wcstod_l (MSVCRT.@)
320 double CDECL
MSVCRT__wcstod_l(const MSVCRT_wchar_t
* str
, MSVCRT_wchar_t
** end
,
321 MSVCRT__locale_t locale
)
323 MSVCRT_pthreadlocinfo locinfo
;
324 unsigned __int64 d
=0, hlp
;
327 const MSVCRT_wchar_t
*p
;
329 long double lret
=1, expcnt
= 10;
330 BOOL found_digit
= FALSE
, negexp
;
332 if (!MSVCRT_CHECK_PMT(str
!= NULL
)) return 0;
335 locinfo
= get_locinfo();
337 locinfo
= locale
->locinfo
;
349 while(isdigitW(*p
)) {
351 hlp
= d
*10+*(p
++)-'0';
352 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
) {
358 while(isdigitW(*p
)) {
362 if(*p
== *locinfo
->lconv
->decimal_point
)
365 while(isdigitW(*p
)) {
367 hlp
= d
*10+*(p
++)-'0';
368 if(d
>MSVCRT_UI64_MAX
/10 || hlp
<d
)
379 *end
= (MSVCRT_wchar_t
*)str
;
383 if(*p
=='e' || *p
=='E' || *p
=='d' || *p
=='D') {
394 while(isdigitW(*p
)) {
395 if(e
>INT_MAX
/10 || (e
=e
*10+*p
-'0')<0)
401 if(exp
<0 && e
<0 && exp
+e
>=0) exp
= INT_MIN
;
402 else if(exp
>0 && e
>0 && exp
+e
<0) exp
= INT_MAX
;
405 if(*p
=='-' || *p
=='+')
411 fpcontrol
= _control87(0, 0);
412 _control87(MSVCRT__EM_DENORMAL
|MSVCRT__EM_INVALID
|MSVCRT__EM_ZERODIVIDE
413 |MSVCRT__EM_OVERFLOW
|MSVCRT__EM_UNDERFLOW
|MSVCRT__EM_INEXACT
, 0xffffffff);
422 expcnt
= expcnt
*expcnt
;
424 ret
= (long double)sign
* (negexp
? d
/lret
: d
*lret
);
426 _control87(fpcontrol
, 0xffffffff);
428 if((d
&& ret
==0.0) || isinf(ret
))
429 *MSVCRT__errno() = MSVCRT_ERANGE
;
432 *end
= (MSVCRT_wchar_t
*)p
;
437 /*********************************************************************
438 * wcsrtombs_l (INTERNAL)
440 static MSVCRT_size_t
MSVCRT_wcsrtombs_l(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
441 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
443 MSVCRT_pthreadlocinfo locinfo
;
444 MSVCRT_size_t tmp
= 0;
448 locinfo
= get_locinfo();
450 locinfo
= locale
->locinfo
;
453 tmp
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
454 *wcstr
, -1, NULL
, 0, NULL
, &used_default
)-1;
455 if(!tmp
|| used_default
) {
456 *MSVCRT__errno() = MSVCRT_EILSEQ
;
464 MSVCRT_size_t i
, size
;
466 size
= WideCharToMultiByte(locinfo
->lc_codepage
, WC_NO_BEST_FIT_CHARS
,
467 *wcstr
, 1, buf
, 3, NULL
, &used_default
);
468 if(!size
|| used_default
) {
469 *MSVCRT__errno() = MSVCRT_EILSEQ
;
475 for(i
=0; i
<size
; i
++)
476 mbstr
[tmp
++] = buf
[i
];
487 /*********************************************************************
488 * _wcstombs_l (MSVCRT.@)
490 MSVCRT_size_t CDECL
MSVCRT__wcstombs_l(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
491 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
493 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, locale
);
496 /*********************************************************************
497 * wcstombs (MSVCRT.@)
499 MSVCRT_size_t CDECL
MSVCRT_wcstombs(char *mbstr
, const MSVCRT_wchar_t
*wcstr
,
502 return MSVCRT_wcsrtombs_l(mbstr
, &wcstr
, count
, NULL
);
505 /*********************************************************************
506 * wcsrtombs (MSVCRT.@)
508 MSVCRT_size_t CDECL
MSVCRT_wcsrtombs(char *mbstr
, const MSVCRT_wchar_t
**wcstr
,
509 MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
514 return MSVCRT_wcsrtombs_l(mbstr
, wcstr
, count
, NULL
);
517 /*********************************************************************
518 * MSVCRT_wcsrtombs_s_l (INTERNAL)
520 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
521 MSVCRT_size_t size
, const MSVCRT_wchar_t
**wcstr
,
522 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
526 if(!mbstr
&& !size
&& wcstr
) {
527 conv
= MSVCRT_wcsrtombs_l(NULL
, wcstr
, 0, locale
);
529 return *MSVCRT__errno();
535 if (!MSVCRT_CHECK_PMT(mbstr
!= NULL
)) return MSVCRT_EINVAL
;
536 if (size
) mbstr
[0] = '\0';
537 if (!MSVCRT_CHECK_PMT(wcstr
!= NULL
)) return MSVCRT_EINVAL
;
538 if (!MSVCRT_CHECK_PMT(*wcstr
!= NULL
)) return MSVCRT_EINVAL
;
540 if(count
==MSVCRT__TRUNCATE
|| size
<count
)
545 conv
= MSVCRT_wcsrtombs_l(mbstr
, wcstr
, conv
, locale
);
549 return *MSVCRT__errno();
550 }else if(conv
< size
)
551 mbstr
[conv
++] = '\0';
552 else if(conv
==size
&& (count
==MSVCRT__TRUNCATE
|| mbstr
[conv
-1]=='\0'))
553 mbstr
[conv
-1] = '\0';
555 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE
);
558 return MSVCRT_ERANGE
;
566 /*********************************************************************
567 * _wcstombs_s_l (MSVCRT.@)
569 int CDECL
MSVCRT__wcstombs_s_l(MSVCRT_size_t
*ret
, char *mbstr
,
570 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
,
571 MSVCRT_size_t count
, MSVCRT__locale_t locale
)
573 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
,count
, locale
);
576 /*********************************************************************
577 * wcstombs_s (MSVCRT.@)
579 int CDECL
MSVCRT_wcstombs_s(MSVCRT_size_t
*ret
, char *mbstr
,
580 MSVCRT_size_t size
, const MSVCRT_wchar_t
*wcstr
, MSVCRT_size_t count
)
582 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, &wcstr
, count
, NULL
);
585 /*********************************************************************
586 * wcsrtombs_s (MSVCRT.@)
588 int CDECL
MSVCRT_wcsrtombs_s(MSVCRT_size_t
*ret
, char *mbstr
, MSVCRT_size_t size
,
589 const MSVCRT_wchar_t
**wcstr
, MSVCRT_size_t count
, MSVCRT_mbstate_t
*mbstate
)
594 return MSVCRT_wcsrtombs_s_l(ret
, mbstr
, size
, wcstr
, count
, NULL
);
597 /*********************************************************************
600 double CDECL
MSVCRT_wcstod(const MSVCRT_wchar_t
* lpszStr
, MSVCRT_wchar_t
** end
)
602 return MSVCRT__wcstod_l(lpszStr
, end
, NULL
);
605 /*********************************************************************
608 double CDECL
MSVCRT__wtof(const MSVCRT_wchar_t
*str
)
610 return MSVCRT__wcstod_l(str
, NULL
, NULL
);
613 /*********************************************************************
616 double CDECL
MSVCRT__wtof_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
618 return MSVCRT__wcstod_l(str
, NULL
, locale
);
621 /*********************************************************************
622 * arg_clbk_valist (INTERNAL)
624 printf_arg
arg_clbk_valist(void *ctx
, int arg_pos
, int type
, __ms_va_list
*valist
)
629 ret
.get_longlong
= va_arg(*valist
, LONGLONG
);
630 else if(type
== VT_INT
)
631 ret
.get_int
= va_arg(*valist
, int);
632 else if(type
== VT_R8
)
633 ret
.get_double
= va_arg(*valist
, double);
634 else if(type
== VT_PTR
)
635 ret
.get_ptr
= va_arg(*valist
, void*);
637 ERR("Incorrect type\n");
644 /*********************************************************************
645 * arg_clbk_positional (INTERNAL)
647 static printf_arg
arg_clbk_positional(void *ctx
, int pos
, int type
, __ms_va_list
*valist
)
649 printf_arg
*args
= ctx
;
653 /*********************************************************************
654 * _vsnprintf (MSVCRT.@)
656 int CDECL
MSVCRT_vsnprintf( char *str
, MSVCRT_size_t len
,
657 const char *format
, __ms_va_list valist
)
659 static const char nullbyte
= '\0';
660 struct _str_ctx_a ctx
= {len
, str
};
663 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, NULL
, FALSE
, FALSE
,
664 arg_clbk_valist
, NULL
, &valist
);
665 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
669 /*********************************************************************
670 * _vsnprintf_l (MSVCRT.@)
672 int CDECL
MSVCRT_vsnprintf_l( char *str
, MSVCRT_size_t len
, const char *format
,
673 MSVCRT__locale_t locale
, __ms_va_list valist
)
675 static const char nullbyte
= '\0';
676 struct _str_ctx_a ctx
= {len
, str
};
679 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, FALSE
,
680 arg_clbk_valist
, NULL
, &valist
);
681 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
685 /*********************************************************************
686 * _vsprintf_l (MSVCRT.@)
688 int CDECL
MSVCRT_vsprintf_l( char *str
, const char *format
,
689 MSVCRT__locale_t locale
, __ms_va_list valist
)
691 return MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
694 /*********************************************************************
695 * _sprintf_l (MSVCRT.@)
697 int CDECL
MSVCRT_sprintf_l(char *str
, const char *format
,
698 MSVCRT__locale_t locale
, ...)
702 __ms_va_start(valist
, locale
);
703 retval
= MSVCRT_vsnprintf_l(str
, INT_MAX
, format
, locale
, valist
);
708 /*********************************************************************
709 * _vsnprintf_s_l (MSVCRT.@)
711 int CDECL
MSVCRT_vsnprintf_s_l( char *str
, MSVCRT_size_t sizeOfBuffer
,
712 MSVCRT_size_t count
, const char *format
,
713 MSVCRT__locale_t locale
, __ms_va_list valist
)
715 static const char nullbyte
= '\0';
716 struct _str_ctx_a ctx
;
719 if(sizeOfBuffer
<count
+1 || count
==-1)
726 ret
= pf_printf_a(puts_clbk_str_a
, &ctx
, format
, locale
, FALSE
, TRUE
,
727 arg_clbk_valist
, NULL
, &valist
);
728 puts_clbk_str_a(&ctx
, 1, &nullbyte
);
730 if(ret
<0 || ret
==len
) {
731 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
732 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
733 memset(str
, 0, sizeOfBuffer
);
743 /*********************************************************************
744 * _vsprintf_s_l (MSVCRT.@)
746 int CDECL
MSVCRT_vsprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
747 MSVCRT__locale_t locale
, __ms_va_list valist
)
749 return MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
752 /*********************************************************************
753 * _sprintf_s_l (MSVCRT.@)
755 int CDECL
MSVCRT_sprintf_s_l( char *str
, MSVCRT_size_t count
, const char *format
,
756 MSVCRT__locale_t locale
, ...)
760 __ms_va_start(valist
, locale
);
761 retval
= MSVCRT_vsnprintf_s_l(str
, INT_MAX
, count
, format
, locale
, valist
);
766 /*********************************************************************
767 * _vsnprintf_s (MSVCRT.@)
769 int CDECL
MSVCRT_vsnprintf_s( char *str
, MSVCRT_size_t sizeOfBuffer
,
770 MSVCRT_size_t count
, const char *format
, __ms_va_list valist
)
772 return MSVCRT_vsnprintf_s_l(str
,sizeOfBuffer
, count
, format
, NULL
, valist
);
775 /*********************************************************************
776 * vsprintf (MSVCRT.@)
778 int CDECL
MSVCRT_vsprintf( char *str
, const char *format
, __ms_va_list valist
)
780 return MSVCRT_vsnprintf(str
, INT_MAX
, format
, valist
);
783 /*********************************************************************
784 * vsprintf_s (MSVCRT.@)
786 int CDECL
MSVCRT_vsprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, __ms_va_list valist
)
788 return MSVCRT_vsnprintf(str
, num
, format
, valist
);
791 /*********************************************************************
792 * _vscprintf (MSVCRT.@)
794 int CDECL
MSVCRT__vscprintf( const char *format
, __ms_va_list valist
)
796 return MSVCRT_vsnprintf( NULL
, INT_MAX
, format
, valist
);
799 /*********************************************************************
800 * _snprintf (MSVCRT.@)
802 int CDECL
MSVCRT__snprintf(char *str
, unsigned int len
, const char *format
, ...)
806 __ms_va_start(valist
, format
);
807 retval
= MSVCRT_vsnprintf(str
, len
, format
, valist
);
812 /*********************************************************************
813 * _snprintf_s (MSVCRT.@)
815 int CDECL
MSVCRT__snprintf_s(char *str
, unsigned int len
, unsigned int count
,
816 const char *format
, ...)
820 __ms_va_start(valist
, format
);
821 retval
= MSVCRT_vsnprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
826 /*********************************************************************
827 * _scprintf (MSVCRT.@)
829 int CDECL
MSVCRT__scprintf(const char *format
, ...)
833 __ms_va_start(valist
, format
);
834 retval
= MSVCRT__vscprintf(format
, valist
);
839 /*********************************************************************
840 * _vsnwprintf (MSVCRT.@)
842 int CDECL
MSVCRT_vsnwprintf(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
843 const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
845 static const MSVCRT_wchar_t nullbyte
= '\0';
846 struct _str_ctx_w ctx
= {len
, str
};
849 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, NULL
, FALSE
, FALSE
,
850 arg_clbk_valist
, NULL
, &valist
);
851 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
855 /*********************************************************************
856 * _vsnwprintf_l (MSVCRT.@)
858 int CDECL
MSVCRT_vsnwprintf_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t len
,
859 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
,
862 static const MSVCRT_wchar_t nullbyte
= '\0';
863 struct _str_ctx_w ctx
= {len
, str
};
866 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, FALSE
,
867 arg_clbk_valist
, NULL
, &valist
);
868 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
872 /*********************************************************************
873 * _vswprintf_p_l (MSVCRT.@)
875 int CDECL
MSVCRT_vswprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
876 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
878 static const MSVCRT_wchar_t nullbyte
= '\0';
879 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
880 struct _str_ctx_w puts_ctx
= {length
, buffer
};
883 memset(args_ctx
, 0, sizeof(args_ctx
));
885 ret
= create_positional_ctx_w(args_ctx
, format
, args
);
887 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
888 *MSVCRT__errno() = MSVCRT_EINVAL
;
891 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
892 arg_clbk_valist
, NULL
, &args
);
894 ret
= pf_printf_w(puts_clbk_str_w
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
895 arg_clbk_positional
, args_ctx
, NULL
);
897 puts_clbk_str_w(&puts_ctx
, 1, &nullbyte
);
901 /*********************************************************************
902 * _vswprintf_p (MSVCR100.@)
904 int CDECL
MSVCRT__vswprintf_p(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
905 const MSVCRT_wchar_t
*format
, __ms_va_list args
)
907 return MSVCRT_vswprintf_p_l(buffer
, length
, format
, NULL
, args
);
910 /*********************************************************************
911 * _vsnwprintf_s_l (MSVCRT.@)
913 int CDECL
MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
914 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
,
915 MSVCRT__locale_t locale
, __ms_va_list valist
)
917 static const MSVCRT_wchar_t nullbyte
= '\0';
918 struct _str_ctx_w ctx
;
922 if(count
!=-1 && len
>count
+1)
927 ret
= pf_printf_w(puts_clbk_str_w
, &ctx
, format
, locale
, FALSE
, TRUE
,
928 arg_clbk_valist
, NULL
, &valist
);
929 puts_clbk_str_w(&ctx
, 1, &nullbyte
);
931 if(ret
<0 || ret
==len
) {
932 if(count
!=MSVCRT__TRUNCATE
&& count
>sizeOfBuffer
) {
933 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE
);
934 memset(str
, 0, sizeOfBuffer
*sizeof(MSVCRT_wchar_t
));
944 /*********************************************************************
945 * _vsnwprintf_s (MSVCRT.@)
947 int CDECL
MSVCRT_vsnwprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t sizeOfBuffer
,
948 MSVCRT_size_t count
, const MSVCRT_wchar_t
*format
, __ms_va_list valist
)
950 return MSVCRT_vsnwprintf_s_l(str
, sizeOfBuffer
, count
,
951 format
, NULL
, valist
);
954 /*********************************************************************
955 * _snwprintf (MSVCRT.@)
957 int CDECL
MSVCRT__snwprintf( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
, ...)
961 __ms_va_start(valist
, format
);
962 retval
= MSVCRT_vsnwprintf(str
, len
, format
, valist
);
967 /*********************************************************************
968 * _snwprintf_l (MSVCRT.@)
970 int CDECL
MSVCRT__snwprintf_l( MSVCRT_wchar_t
*str
, unsigned int len
, const MSVCRT_wchar_t
*format
,
971 MSVCRT__locale_t locale
, ...)
975 __ms_va_start(valist
, locale
);
976 retval
= MSVCRT_vsnwprintf_l(str
, len
, format
, locale
, valist
);
981 /*********************************************************************
982 * _snwprintf_s (MSVCRT.@)
984 int CDECL
MSVCRT__snwprintf_s( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
985 const MSVCRT_wchar_t
*format
, ...)
989 __ms_va_start(valist
, format
);
990 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, NULL
, valist
);
995 /*********************************************************************
996 * _snwprintf_s_l (MSVCRT.@)
998 int CDECL
MSVCRT__snwprintf_s_l( MSVCRT_wchar_t
*str
, unsigned int len
, unsigned int count
,
999 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1002 __ms_va_list valist
;
1003 __ms_va_start(valist
, locale
);
1004 retval
= MSVCRT_vsnwprintf_s_l(str
, len
, count
, format
, locale
, valist
);
1005 __ms_va_end(valist
);
1009 /*********************************************************************
1010 * sprintf (MSVCRT.@)
1012 int CDECL
MSVCRT_sprintf( char *str
, const char *format
, ... )
1017 __ms_va_start( ap
, format
);
1018 r
= MSVCRT_vsnprintf( str
, INT_MAX
, format
, ap
);
1023 /*********************************************************************
1024 * sprintf_s (MSVCRT.@)
1026 int CDECL
MSVCRT_sprintf_s( char *str
, MSVCRT_size_t num
, const char *format
, ... )
1031 __ms_va_start( ap
, format
);
1032 r
= MSVCRT_vsnprintf( str
, num
, format
, ap
);
1037 /*********************************************************************
1038 * _scwprintf (MSVCRT.@)
1040 int CDECL
MSVCRT__scwprintf( const MSVCRT_wchar_t
*format
, ... )
1045 __ms_va_start( ap
, format
);
1046 r
= MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, ap
);
1051 /*********************************************************************
1052 * swprintf (MSVCRT.@)
1054 int CDECL
MSVCRT_swprintf( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*format
, ... )
1059 __ms_va_start( ap
, format
);
1060 r
= MSVCRT_vsnwprintf( str
, INT_MAX
, format
, ap
);
1065 /*********************************************************************
1066 * swprintf_s (MSVCRT.@)
1068 int CDECL
MSVCRT_swprintf_s(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1069 const MSVCRT_wchar_t
*format
, ... )
1074 __ms_va_start(ap
, format
);
1075 r
= MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, ap
);
1081 /*********************************************************************
1082 * _swprintf_s_l (MSVCRT.@)
1084 int CDECL
MSVCRT__swprintf_s_l(MSVCRT_wchar_t
*str
, MSVCRT_size_t numberOfElements
,
1085 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ... )
1090 __ms_va_start(ap
, locale
);
1091 r
= MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
, format
, locale
, ap
);
1097 /*********************************************************************
1098 * _vswprintf (MSVCRT.@)
1100 int CDECL
MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1102 return MSVCRT_vsnwprintf( str
, INT_MAX
, format
, args
);
1105 /*********************************************************************
1106 * _vswprintf (MSVCRT.@)
1108 int CDECL
MSVCRT_vswprintf_l( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
,
1109 MSVCRT__locale_t locale
, __ms_va_list args
)
1111 return MSVCRT_vsnwprintf_l( str
, INT_MAX
, format
, locale
, args
);
1114 /*********************************************************************
1115 * _vscwprintf (MSVCRT.@)
1117 int CDECL
MSVCRT__vscwprintf( const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1119 return MSVCRT_vsnwprintf( NULL
, INT_MAX
, format
, args
);
1122 /*********************************************************************
1123 * _vscwprintf_l (MSVCRT.@)
1125 int CDECL
MSVCRT__vscwprintf_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1127 return MSVCRT_vsnwprintf_l( NULL
, INT_MAX
, format
, locale
, args
);
1130 /*********************************************************************
1131 * _vscwprintf_p_l (MSVCRT.@)
1133 int CDECL
MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1135 return MSVCRT_vswprintf_p_l( NULL
, INT_MAX
, format
, locale
, args
);
1138 /*********************************************************************
1139 * _vscwprintf_p (MSVCR100.@)
1141 int CDECL
MSVCRT__vscwprintf_p(const MSVCRT_wchar_t
*format
, __ms_va_list args
)
1143 return MSVCRT_vswprintf_p_l(NULL
, INT_MAX
, format
, NULL
, args
);
1146 /*********************************************************************
1147 * vswprintf_s (MSVCRT.@)
1149 int CDECL
MSVCRT_vswprintf_s(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1150 const MSVCRT_wchar_t
* format
, __ms_va_list args
)
1152 return MSVCRT_vsnwprintf_s(str
, numberOfElements
, INT_MAX
, format
, args
);
1155 /*********************************************************************
1156 * _vswprintf_s_l (MSVCRT.@)
1158 int CDECL
MSVCRT_vswprintf_s_l(MSVCRT_wchar_t
* str
, MSVCRT_size_t numberOfElements
,
1159 const MSVCRT_wchar_t
* format
, MSVCRT__locale_t locale
, __ms_va_list args
)
1161 return MSVCRT_vsnwprintf_s_l(str
, numberOfElements
, INT_MAX
,
1162 format
, locale
, args
);
1165 /*********************************************************************
1166 * _vsprintf_p_l (MSVCRT.@)
1168 int CDECL
MSVCRT_vsprintf_p_l(char *buffer
, MSVCRT_size_t length
, const char *format
,
1169 MSVCRT__locale_t locale
, __ms_va_list args
)
1171 static const char nullbyte
= '\0';
1172 printf_arg args_ctx
[MSVCRT__ARGMAX
+1];
1173 struct _str_ctx_a puts_ctx
= {length
, buffer
};
1176 memset(args_ctx
, 0, sizeof(args_ctx
));
1178 ret
= create_positional_ctx_a(args_ctx
, format
, args
);
1180 MSVCRT__invalid_parameter(NULL
, NULL
, NULL
, 0, 0);
1181 *MSVCRT__errno() = MSVCRT_EINVAL
;
1184 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, FALSE
, TRUE
,
1185 arg_clbk_valist
, NULL
, &args
);
1187 ret
= pf_printf_a(puts_clbk_str_a
, &puts_ctx
, format
, locale
, TRUE
, TRUE
,
1188 arg_clbk_positional
, args_ctx
, NULL
);
1190 puts_clbk_str_a(&puts_ctx
, 1, &nullbyte
);
1194 /*********************************************************************
1195 * _vsprintf_p (MSVCRT.@)
1197 int CDECL
MSVCRT_vsprintf_p(char *buffer
, MSVCRT_size_t length
,
1198 const char *format
, __ms_va_list args
)
1200 return MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, args
);
1203 /*********************************************************************
1204 * _sprintf_p_l (MSVCRT.@)
1206 int CDECL
MSVCRT_sprintf_p_l(char *buffer
, MSVCRT_size_t length
,
1207 const char *format
, MSVCRT__locale_t locale
, ...)
1209 __ms_va_list valist
;
1212 __ms_va_start(valist
, locale
);
1213 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, locale
, valist
);
1214 __ms_va_end(valist
);
1219 /*********************************************************************
1220 * _sprintf_p (MSVCR100.@)
1222 int CDECL
MSVCRT__sprintf_p(char *buffer
, MSVCRT_size_t length
, const char *format
, ...)
1224 __ms_va_list valist
;
1227 __ms_va_start(valist
, format
);
1228 r
= MSVCRT_vsprintf_p_l(buffer
, length
, format
, NULL
, valist
);
1229 __ms_va_end(valist
);
1234 /*********************************************************************
1235 * _swprintf_p_l (MSVCRT.@)
1237 int CDECL
MSVCRT_swprintf_p_l(MSVCRT_wchar_t
*buffer
, MSVCRT_size_t length
,
1238 const MSVCRT_wchar_t
*format
, MSVCRT__locale_t locale
, ...)
1240 __ms_va_list valist
;
1243 __ms_va_start(valist
, locale
);
1244 r
= MSVCRT_vswprintf_p_l(buffer
, length
, format
, locale
, valist
);
1245 __ms_va_end(valist
);
1250 /*********************************************************************
1251 * _wcscoll_l (MSVCRT.@)
1253 int CDECL
MSVCRT__wcscoll_l(const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
, MSVCRT__locale_t locale
)
1255 MSVCRT_pthreadlocinfo locinfo
;
1258 locinfo
= get_locinfo();
1260 locinfo
= locale
->locinfo
;
1262 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
])
1263 return strcmpW(str1
, str2
);
1264 return CompareStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
], 0, str1
, -1, str2
, -1)-CSTR_EQUAL
;
1267 /*********************************************************************
1268 * wcscoll (MSVCRT.@)
1270 int CDECL
MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
1272 return MSVCRT__wcscoll_l(str1
, str2
, NULL
);
1275 /*********************************************************************
1276 * wcspbrk (MSVCRT.@)
1278 MSVCRT_wchar_t
* CDECL
MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
1280 const MSVCRT_wchar_t
* p
;
1284 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
1290 /*********************************************************************
1291 * wcstok_s (MSVCRT.@)
1293 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok_s( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
,
1294 MSVCRT_wchar_t
**next_token
)
1296 MSVCRT_wchar_t
*ret
;
1298 if (!MSVCRT_CHECK_PMT(delim
!= NULL
)) return NULL
;
1299 if (!MSVCRT_CHECK_PMT(next_token
!= NULL
)) return NULL
;
1300 if (!MSVCRT_CHECK_PMT(str
!= NULL
|| *next_token
!= NULL
)) return NULL
;
1302 if (!str
) str
= *next_token
;
1304 while (*str
&& strchrW( delim
, *str
)) str
++;
1305 if (!*str
) return NULL
;
1307 while (*str
&& !strchrW( delim
, *str
)) str
++;
1308 if (*str
) *str
++ = 0;
1313 /*********************************************************************
1316 MSVCRT_wchar_t
* CDECL
MSVCRT_wcstok( MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*delim
)
1318 return MSVCRT_wcstok_s(str
, delim
, &msvcrt_get_thread_data()->wcstok_next
);
1321 /*********************************************************************
1322 * _wctomb_s_l (MSVCRT.@)
1324 int CDECL
MSVCRT__wctomb_s_l(int *len
, char *mbchar
, MSVCRT_size_t size
,
1325 MSVCRT_wchar_t wch
, MSVCRT__locale_t locale
)
1327 MSVCRT_pthreadlocinfo locinfo
;
1331 if(!mbchar
&& size
>0) {
1340 if(!MSVCRT_CHECK_PMT(size
<= INT_MAX
))
1341 return MSVCRT_EINVAL
;
1344 locinfo
= get_locinfo();
1346 locinfo
= locale
->locinfo
;
1348 if(!locinfo
->lc_codepage
) {
1350 if(mbchar
&& size
>0)
1351 memset(mbchar
, 0, size
);
1352 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1353 return MSVCRT_EILSEQ
;
1356 if(!MSVCRT_CHECK_PMT_ERR(size
>= 1, MSVCRT_ERANGE
))
1357 return MSVCRT_ERANGE
;
1365 mblen
= WideCharToMultiByte(locinfo
->lc_codepage
, 0, &wch
, 1, mbchar
, size
, NULL
, &error
);
1366 if(!mblen
|| error
) {
1367 if(!mblen
&& GetLastError()==ERROR_INSUFFICIENT_BUFFER
) {
1368 if(mbchar
&& size
>0)
1369 memset(mbchar
, 0, size
);
1371 MSVCRT_INVALID_PMT("insufficient buffer size", MSVCRT_ERANGE
);
1372 return MSVCRT_ERANGE
;
1375 *MSVCRT__errno() = MSVCRT_EILSEQ
;
1376 return MSVCRT_EILSEQ
;
1384 /*********************************************************************
1385 * wctomb_s (MSVCRT.@)
1387 int CDECL
MSVCRT_wctomb_s(int *len
, char *mbchar
, MSVCRT_size_t size
, MSVCRT_wchar_t wch
)
1389 return MSVCRT__wctomb_s_l(len
, mbchar
, size
, wch
, NULL
);
1392 /*********************************************************************
1393 * _wctomb_l (MSVCRT.@)
1395 int CDECL
MSVCRT__wctomb_l(char *dst
, MSVCRT_wchar_t ch
, MSVCRT__locale_t locale
)
1399 MSVCRT__wctomb_s_l(&len
, dst
, dst
? 6 : 0, ch
, locale
);
1403 /*********************************************************************
1406 INT CDECL
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
1408 return MSVCRT__wctomb_l(dst
, ch
, NULL
);
1411 /*********************************************************************
1414 INT CDECL
MSVCRT_wctob( MSVCRT_wint_t wchar
)
1418 UINT codepage
= get_locinfo()->lc_codepage
;
1422 return (signed char)wchar
;
1425 } else if(WideCharToMultiByte( codepage
, 0, &wchar
, 1, &out
, 1, NULL
, &error
) && !error
)
1430 /*********************************************************************
1431 * wcrtomb (MSVCRT.@)
1433 MSVCRT_size_t CDECL
MSVCRT_wcrtomb( char *dst
, MSVCRT_wchar_t ch
, MSVCRT_mbstate_t
*s
)
1437 return MSVCRT_wctomb(dst
, ch
);
1440 /*********************************************************************
1441 * iswalnum (MSVCRT.@)
1443 INT CDECL
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
1445 return isalnumW( wc
);
1448 /*********************************************************************
1449 * iswalpha (MSVCRT.@)
1451 INT CDECL
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
1453 return isalphaW( wc
);
1456 /*********************************************************************
1457 * iswalpha_l (MSVCRT.@)
1459 INT CDECL
MSVCRT__iswalpha_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1461 return isalphaW( wc
);
1464 /*********************************************************************
1465 * iswcntrl (MSVCRT.@)
1467 INT CDECL
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
1469 return iscntrlW( wc
);
1472 /*********************************************************************
1473 * iswdigit (MSVCRT.@)
1475 INT CDECL
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
1477 return isdigitW( wc
);
1480 /*********************************************************************
1481 * _iswdigit_l (MSVCRT.@)
1483 INT CDECL
MSVCRT__iswdigit_l( MSVCRT_wchar_t wc
, MSVCRT__locale_t locale
)
1485 return isdigitW( wc
);
1488 /*********************************************************************
1489 * iswgraph (MSVCRT.@)
1491 INT CDECL
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
1493 return isgraphW( wc
);
1496 /*********************************************************************
1497 * iswlower (MSVCRT.@)
1499 INT CDECL
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
1501 return islowerW( wc
);
1504 /*********************************************************************
1505 * iswprint (MSVCRT.@)
1507 INT CDECL
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
1509 return isprintW( wc
);
1512 /*********************************************************************
1513 * iswpunct (MSVCRT.@)
1515 INT CDECL
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
1517 return ispunctW( wc
);
1520 /*********************************************************************
1521 * iswspace (MSVCRT.@)
1523 INT CDECL
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
1525 return isspaceW( wc
);
1528 /*********************************************************************
1529 * iswupper (MSVCRT.@)
1531 INT CDECL
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
1533 return isupperW( wc
);
1536 /*********************************************************************
1537 * iswxdigit (MSVCRT.@)
1539 INT CDECL
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
1541 return isxdigitW( wc
);
1544 /*********************************************************************
1545 * wcscpy_s (MSVCRT.@)
1547 INT CDECL
MSVCRT_wcscpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
)
1549 MSVCRT_size_t size
= 0;
1551 if(!MSVCRT_CHECK_PMT(wcDest
)) return MSVCRT_EINVAL
;
1552 if(!MSVCRT_CHECK_PMT(numElement
)) return MSVCRT_EINVAL
;
1556 if(!MSVCRT_CHECK_PMT(wcSrc
)) return MSVCRT_EINVAL
;
1558 size
= strlenW(wcSrc
) + 1;
1560 if(!MSVCRT_CHECK_PMT_ERR(size
<= numElement
, MSVCRT_ERANGE
))
1561 return MSVCRT_ERANGE
;
1563 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1568 /******************************************************************
1569 * wcsncpy (MSVCRT.@)
1571 MSVCRT_wchar_t
* __cdecl
MSVCRT_wcsncpy( MSVCRT_wchar_t
* s1
,
1572 const MSVCRT_wchar_t
*s2
, MSVCRT_size_t n
)
1577 if(!(s1
[i
] = s2
[i
])) break;
1583 /******************************************************************
1584 * wcsncpy_s (MSVCRT.@)
1586 INT CDECL
MSVCRT_wcsncpy_s( MSVCRT_wchar_t
* wcDest
, MSVCRT_size_t numElement
, const MSVCRT_wchar_t
*wcSrc
,
1587 MSVCRT_size_t count
)
1590 BOOL truncate
= (count
== MSVCRT__TRUNCATE
);
1592 if(!wcDest
&& !numElement
&& !count
)
1595 if (!wcDest
|| !numElement
)
1596 return MSVCRT_EINVAL
;
1601 return count
? MSVCRT_EINVAL
: 0;
1604 while (numElement
&& count
&& *wcSrc
)
1610 if (!numElement
&& truncate
)
1613 return MSVCRT_STRUNCATE
;
1615 else if (!numElement
)
1618 return MSVCRT_ERANGE
;
1625 /******************************************************************
1626 * wcscat_s (MSVCRT.@)
1629 INT CDECL
MSVCRT_wcscat_s(MSVCRT_wchar_t
* dst
, MSVCRT_size_t elem
, const MSVCRT_wchar_t
* src
)
1631 MSVCRT_wchar_t
* ptr
= dst
;
1633 if (!dst
|| elem
== 0) return MSVCRT_EINVAL
;
1637 return MSVCRT_EINVAL
;
1640 /* seek to end of dst string (or elem if no end of string is found */
1641 while (ptr
< dst
+ elem
&& *ptr
!= '\0') ptr
++;
1642 while (ptr
< dst
+ elem
)
1644 if ((*ptr
++ = *src
++) == '\0') return 0;
1646 /* not enough space */
1648 return MSVCRT_ERANGE
;
1651 /*********************************************************************
1652 * wcsncat_s (MSVCRT.@)
1655 INT CDECL
MSVCRT_wcsncat_s(MSVCRT_wchar_t
*dst
, MSVCRT_size_t elem
,
1656 const MSVCRT_wchar_t
*src
, MSVCRT_size_t count
)
1658 MSVCRT_size_t srclen
;
1659 MSVCRT_wchar_t dststart
;
1662 if (!MSVCRT_CHECK_PMT(dst
!= NULL
)) return MSVCRT_EINVAL
;
1663 if (!MSVCRT_CHECK_PMT(elem
> 0)) return MSVCRT_EINVAL
;
1664 if (!MSVCRT_CHECK_PMT(src
!= NULL
|| count
== 0)) return MSVCRT_EINVAL
;
1669 for (dststart
= 0; dststart
< elem
; dststart
++)
1671 if (dst
[dststart
] == '\0')
1674 if (dststart
== elem
)
1676 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL
);
1677 return MSVCRT_EINVAL
;
1680 if (count
== MSVCRT__TRUNCATE
)
1682 srclen
= strlenW(src
);
1683 if (srclen
>= (elem
- dststart
))
1685 srclen
= elem
- dststart
- 1;
1686 ret
= MSVCRT_STRUNCATE
;
1690 srclen
= min(strlenW(src
), count
);
1691 if (srclen
< (elem
- dststart
))
1693 memcpy(&dst
[dststart
], src
, srclen
*sizeof(MSVCRT_wchar_t
));
1694 dst
[dststart
+srclen
] = '\0';
1697 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE
);
1699 return MSVCRT_ERANGE
;
1702 /*********************************************************************
1703 * _wcstoi64_l (MSVCRT.@)
1705 * FIXME: locale parameter is ignored
1707 __int64 CDECL
MSVCRT__wcstoi64_l(const MSVCRT_wchar_t
*nptr
,
1708 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1710 BOOL negative
= FALSE
;
1713 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1715 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1716 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1717 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1719 while(isspaceW(*nptr
)) nptr
++;
1724 } else if(*nptr
== '+')
1727 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1740 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1748 if(cur
<'a' || cur
>='a'+base
-10)
1758 if(!negative
&& (ret
>MSVCRT_I64_MAX
/base
|| ret
*base
>MSVCRT_I64_MAX
-v
)) {
1759 ret
= MSVCRT_I64_MAX
;
1760 *MSVCRT__errno() = MSVCRT_ERANGE
;
1761 } else if(negative
&& (ret
<MSVCRT_I64_MIN
/base
|| ret
*base
<MSVCRT_I64_MIN
-v
)) {
1762 ret
= MSVCRT_I64_MIN
;
1763 *MSVCRT__errno() = MSVCRT_ERANGE
;
1769 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1774 /*********************************************************************
1775 * _wcstoi64 (MSVCRT.@)
1777 __int64 CDECL
MSVCRT__wcstoi64(const MSVCRT_wchar_t
*nptr
,
1778 MSVCRT_wchar_t
**endptr
, int base
)
1780 return MSVCRT__wcstoi64_l(nptr
, endptr
, base
, NULL
);
1783 /*********************************************************************
1784 * _wcstol_l (MSVCRT.@)
1786 MSVCRT_long CDECL
MSVCRT__wcstol_l(const MSVCRT_wchar_t
*s
,
1787 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1789 __int64 ret
= MSVCRT__wcstoi64_l(s
, end
, base
, locale
);
1791 if(ret
> MSVCRT_LONG_MAX
) {
1792 ret
= MSVCRT_LONG_MAX
;
1793 *MSVCRT__errno() = MSVCRT_ERANGE
;
1794 }else if(ret
< MSVCRT_LONG_MIN
) {
1795 ret
= MSVCRT_LONG_MIN
;
1796 *MSVCRT__errno() = MSVCRT_ERANGE
;
1801 /*********************************************************************
1802 * _wtoi_l (MSVCRT.@)
1804 int __cdecl
MSVCRT__wtoi_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1806 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1810 *MSVCRT__errno() = MSVCRT_ERANGE
;
1811 } else if(ret
< INT_MIN
) {
1813 *MSVCRT__errno() = MSVCRT_ERANGE
;
1818 /*********************************************************************
1821 int __cdecl
MSVCRT__wtoi(const MSVCRT_wchar_t
*str
)
1823 return MSVCRT__wtoi_l(str
, NULL
);
1826 /*********************************************************************
1827 * _wtol_l (MSVCRT.@)
1829 MSVCRT_long __cdecl
MSVCRT__wtol_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
1831 __int64 ret
= MSVCRT__wcstoi64_l(str
, NULL
, 10, locale
);
1833 if(ret
> MSVCRT_LONG_MAX
) {
1834 ret
= MSVCRT_LONG_MAX
;
1835 *MSVCRT__errno() = MSVCRT_ERANGE
;
1836 } else if(ret
< MSVCRT_LONG_MIN
) {
1837 ret
= MSVCRT_LONG_MIN
;
1838 *MSVCRT__errno() = MSVCRT_ERANGE
;
1843 /*********************************************************************
1846 MSVCRT_long __cdecl
MSVCRT__wtol(const MSVCRT_wchar_t
*str
)
1848 return MSVCRT__wtol_l(str
, NULL
);
1851 /*********************************************************************
1852 * _wcstoui64_l (MSVCRT.@)
1854 * FIXME: locale parameter is ignored
1856 unsigned __int64 CDECL
MSVCRT__wcstoui64_l(const MSVCRT_wchar_t
*nptr
,
1857 MSVCRT_wchar_t
**endptr
, int base
, MSVCRT__locale_t locale
)
1859 BOOL negative
= FALSE
;
1860 unsigned __int64 ret
= 0;
1862 TRACE("(%s %p %d %p)\n", debugstr_w(nptr
), endptr
, base
, locale
);
1864 if (!MSVCRT_CHECK_PMT(nptr
!= NULL
)) return 0;
1865 if (!MSVCRT_CHECK_PMT(base
== 0 || base
>= 2)) return 0;
1866 if (!MSVCRT_CHECK_PMT(base
<= 36)) return 0;
1868 while(isspaceW(*nptr
)) nptr
++;
1873 } else if(*nptr
== '+')
1876 if((base
==0 || base
==16) && *nptr
=='0' && tolowerW(*(nptr
+1))=='x') {
1889 MSVCRT_wchar_t cur
= tolowerW(*nptr
);
1897 if(cur
<'a' || cur
>='a'+base
-10)
1904 if(ret
>MSVCRT_UI64_MAX
/base
|| ret
*base
>MSVCRT_UI64_MAX
-v
) {
1905 ret
= MSVCRT_UI64_MAX
;
1906 *MSVCRT__errno() = MSVCRT_ERANGE
;
1912 *endptr
= (MSVCRT_wchar_t
*)nptr
;
1914 return negative
? -ret
: ret
;
1917 /*********************************************************************
1918 * _wcstoui64 (MSVCRT.@)
1920 unsigned __int64 CDECL
MSVCRT__wcstoui64(const MSVCRT_wchar_t
*nptr
,
1921 MSVCRT_wchar_t
**endptr
, int base
)
1923 return MSVCRT__wcstoui64_l(nptr
, endptr
, base
, NULL
);
1926 /*********************************************************************
1927 * _wcstoul_l (MSVCRT.@)
1929 MSVCRT_ulong __cdecl
MSVCRT__wcstoul_l(const MSVCRT_wchar_t
*s
,
1930 MSVCRT_wchar_t
**end
, int base
, MSVCRT__locale_t locale
)
1932 __int64 ret
= MSVCRT__wcstoui64_l(s
, end
, base
, locale
);
1934 if(ret
> MSVCRT_ULONG_MAX
) {
1935 ret
= MSVCRT_ULONG_MAX
;
1936 *MSVCRT__errno() = MSVCRT_ERANGE
;
1941 /*********************************************************************
1942 * wcstoul (MSVCRT.@)
1944 MSVCRT_ulong __cdecl
MSVCRT_wcstoul(const MSVCRT_wchar_t
*s
, MSVCRT_wchar_t
**end
, int base
)
1946 return MSVCRT__wcstoul_l(s
, end
, base
, NULL
);
1949 /******************************************************************
1950 * wcsnlen (MSVCRT.@)
1952 MSVCRT_size_t CDECL
MSVCRT_wcsnlen(const MSVCRT_wchar_t
*s
, MSVCRT_size_t maxlen
)
1956 for (i
= 0; i
< maxlen
; i
++)
1961 /*********************************************************************
1962 * _towupper_l (MSVCRT.@)
1964 int CDECL
MSVCRT__towupper_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1969 /*********************************************************************
1970 * towupper (MSVCRT.@)
1972 int CDECL
MSVCRT_towupper(MSVCRT_wint_t c
)
1974 return MSVCRT__towupper_l(c
, NULL
);
1977 /*********************************************************************
1978 * _towlower_l (MSVCRT.@)
1980 int CDECL
MSVCRT__towlower_l(MSVCRT_wint_t c
, MSVCRT__locale_t locale
)
1985 /*********************************************************************
1986 * towlower (MSVCRT.@)
1988 int CDECL
MSVCRT_towlower(MSVCRT_wint_t c
)
1990 return MSVCRT__towlower_l(c
, NULL
);
1993 /*********************************************************************
1996 MSVCRT_wchar_t
* CDECL
MSVCRT_wcschr(const MSVCRT_wchar_t
*str
, MSVCRT_wchar_t ch
)
1998 return strchrW(str
, ch
);
2001 /***********************************************************************
2004 int CDECL
MSVCRT_wcslen(const MSVCRT_wchar_t
*str
)
2006 return strlenW(str
);
2009 /*********************************************************************
2012 MSVCRT_wchar_t
* CDECL
MSVCRT_wcsstr(const MSVCRT_wchar_t
*str
, const MSVCRT_wchar_t
*sub
)
2014 return strstrW(str
, sub
);
2017 /*********************************************************************
2018 * _wtoi64_l (MSVCRT.@)
2020 __int64 CDECL
MSVCRT__wtoi64_l(const MSVCRT_wchar_t
*str
, MSVCRT__locale_t locale
)
2022 ULONGLONG RunningTotal
= 0;
2023 BOOL bMinus
= FALSE
;
2025 while (isspaceW(*str
)) {
2031 } else if (*str
== '-') {
2036 while (*str
>= '0' && *str
<= '9') {
2037 RunningTotal
= RunningTotal
* 10 + *str
- '0';
2041 return bMinus
? -RunningTotal
: RunningTotal
;
2044 /*********************************************************************
2045 * _wtoi64 (MSVCRT.@)
2047 __int64 CDECL
MSVCRT__wtoi64(const MSVCRT_wchar_t
*str
)
2049 return MSVCRT__wtoi64_l(str
, NULL
);
2052 /*********************************************************************
2053 * wcsncmp (MSVCRT.@)
2055 int CDECL
MSVCRT_wcsncmp(const MSVCRT_wchar_t
*str1
, const MSVCRT_wchar_t
*str2
, int n
)
2057 return strncmpW(str1
, str2
, n
);
2060 /*********************************************************************
2061 * _wcsxfrm_l (MSVCRT.@)
2063 MSVCRT_size_t CDECL
MSVCRT__wcsxfrm_l(MSVCRT_wchar_t
*dest
, const MSVCRT_wchar_t
*src
,
2064 MSVCRT_size_t len
, MSVCRT__locale_t locale
)
2066 MSVCRT_pthreadlocinfo locinfo
;
2069 if(!MSVCRT_CHECK_PMT(src
)) return INT_MAX
;
2070 if(!MSVCRT_CHECK_PMT(dest
|| !len
)) return INT_MAX
;
2073 FIXME("len > INT_MAX not supported\n");
2078 locinfo
= get_locinfo();
2080 locinfo
= locale
->locinfo
;
2082 if(!locinfo
->lc_handle
[MSVCRT_LC_COLLATE
]) {
2083 MSVCRT_wcsncpy(dest
, src
, len
);
2084 return strlenW(src
);
2087 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2088 LCMAP_SORTKEY
, src
, -1, NULL
, 0);
2090 if(len
) dest
[0] = 0;
2091 *MSVCRT__errno() = MSVCRT_EILSEQ
;
2094 if(!len
) return ret
-1;
2098 *MSVCRT__errno() = MSVCRT_ERANGE
;
2102 ret
= LCMapStringW(locinfo
->lc_handle
[MSVCRT_LC_COLLATE
],
2103 LCMAP_SORTKEY
, src
, -1, dest
, len
) - 1;
2104 for(i
=ret
; i
>=0; i
--)
2105 dest
[i
] = ((unsigned char*)dest
)[i
];
2109 /*********************************************************************
2110 * wcsxfrm (MSVCRT.@)
2112 MSVCRT_size_t CDECL
MSVCRT_wcsxfrm(MSVCRT_wchar_t
*dest
,
2113 const MSVCRT_wchar_t
*src
, MSVCRT_size_t len
)
2115 return MSVCRT__wcsxfrm_l(dest
, src
, len
, NULL
);