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);
41 /*********************************************************************
44 MSVCRT_wchar_t* CDECL _wcsdup( const MSVCRT_wchar_t* str )
46 MSVCRT_wchar_t* ret = NULL;
49 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
50 ret = MSVCRT_malloc( size );
51 if (ret) memcpy( ret, str, size );
56 /*********************************************************************
57 * _wcsicoll (MSVCRT.@)
59 INT CDECL _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
61 /* FIXME: handle collates */
62 return strcmpiW( str1, str2 );
65 /*********************************************************************
66 * _wcsnicoll (MSVCRT.@)
68 INT CDECL _wcsnicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count )
70 /* FIXME: handle collates */
71 return strncmpiW( str1, str2, count );
74 /*********************************************************************
77 MSVCRT_wchar_t* CDECL MSVCRT__wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
79 MSVCRT_wchar_t* ret = str;
80 while ((n-- > 0) && *str) *str++ = c;
84 /*********************************************************************
87 MSVCRT_wchar_t* CDECL _wcsrev( MSVCRT_wchar_t* str )
89 MSVCRT_wchar_t* ret = str;
90 MSVCRT_wchar_t* end = str + strlenW(str) - 1;
93 MSVCRT_wchar_t t = *end;
100 /*********************************************************************
103 MSVCRT_wchar_t* CDECL _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
105 MSVCRT_wchar_t* ret = str;
106 while (*str) *str++ = c;
110 /******************************************************************
111 * _wcsupr_s_l (MSVCRT.@)
113 int CDECL MSVCRT__wcsupr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n,
114 MSVCRT__locale_t locale )
116 MSVCRT_wchar_t* ptr = str;
120 if (str) *str = '\0';
121 *MSVCRT__errno() = MSVCRT_EINVAL;
122 return MSVCRT_EINVAL;
128 /* FIXME: add locale support */
129 *ptr = toupperW(*ptr);
133 /* MSDN claims that the function should return and set errno to
134 * ERANGE, which doesn't seem to be true based on the tests. */
136 *MSVCRT__errno() = MSVCRT_EINVAL;
137 return MSVCRT_EINVAL;
140 /******************************************************************
141 * _wcsupr_s (MSVCRT.@)
144 INT CDECL MSVCRT__wcsupr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
146 return MSVCRT__wcsupr_s_l( str, n, NULL );
149 /******************************************************************
150 * _wcslwr_s (MSVCRT.@)
152 int CDECL MSVCRT__wcslwr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
154 MSVCRT_wchar_t* ptr = str;
158 if (str) *str = '\0';
159 *MSVCRT__errno() = MSVCRT_EINVAL;
160 return MSVCRT_EINVAL;
166 *ptr = tolowerW(*ptr);
170 /* MSDN claims that the function should return and set errno to
171 * ERANGE, which doesn't seem to be true based on the tests. */
173 *MSVCRT__errno() = MSVCRT_EINVAL;
174 return MSVCRT_EINVAL;
177 /*********************************************************************
178 * _wcstod_l - not exported in native msvcrt
180 double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
181 MSVCRT__locale_t locale)
183 unsigned __int64 d=0, hlp;
186 const MSVCRT_wchar_t *p;
188 BOOL found_digit = FALSE;
190 if (!MSVCRT_CHECK_PMT(str != NULL)) {
191 *MSVCRT__errno() = MSVCRT_EINVAL;
196 locale = get_locale();
208 while(isdigitW(*p)) {
210 hlp = d*10+*(p++)-'0';
211 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
217 while(isdigitW(*p)) {
221 if(*p == *locale->locinfo->lconv->decimal_point)
224 while(isdigitW(*p)) {
226 hlp = d*10+*(p++)-'0';
227 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
238 *end = (MSVCRT_wchar_t*)str;
242 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
253 while(isdigitW(*p)) {
254 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
260 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
261 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
264 if(*p=='-' || *p=='+')
270 fpcontrol = _control87(0, 0);
271 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
272 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
275 ret = (double)sign*d*pow(10, exp);
277 ret = (double)sign*d/pow(10, -exp);
279 _control87(fpcontrol, 0xffffffff);
281 if((d && ret==0.0) || isinf(ret))
282 *MSVCRT__errno() = MSVCRT_ERANGE;
285 *end = (MSVCRT_wchar_t*)p;
290 /*********************************************************************
291 * _wcstombs_l (MSVCRT.@)
293 MSVCRT_size_t CDECL MSVCRT__wcstombs_l(char *mbstr, const MSVCRT_wchar_t *wcstr,
294 MSVCRT_size_t count, MSVCRT__locale_t locale)
296 char default_char = '\0';
297 MSVCRT_size_t tmp = 0;
301 locale = get_locale();
304 return WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
305 wcstr, -1, NULL, 0, &default_char, &used_default)-1;
309 MSVCRT_size_t i, size;
311 size = WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
312 wcstr, 1, buf, 3, &default_char, &used_default);
318 for(i=0; i<size; i++)
319 mbstr[tmp++] = buf[i];
328 /*********************************************************************
329 * wcstombs (MSVCRT.@)
331 MSVCRT_size_t CDECL MSVCRT_wcstombs(char *mbstr, const MSVCRT_wchar_t *wcstr,
334 return MSVCRT__wcstombs_l(mbstr, wcstr, count, NULL);
337 /*********************************************************************
338 * _wcstombs_s_l (MSVCRT.@)
340 MSVCRT_size_t CDECL MSVCRT__wcstombs_s_l(MSVCRT_size_t *ret, char *mbstr,
341 MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr,
342 MSVCRT_size_t count, MSVCRT__locale_t locale)
346 if(!mbstr && !size) {
347 conv = MSVCRT__wcstombs_l(NULL, wcstr, 0, locale);
353 if (!MSVCRT_CHECK_PMT(wcstr != NULL) || !MSVCRT_CHECK_PMT(mbstr != NULL)) {
356 *MSVCRT__errno() = MSVCRT_EINVAL;
357 return MSVCRT_EINVAL;
360 if(count==MSVCRT__TRUNCATE || size<count)
365 conv = MSVCRT__wcstombs_l(mbstr, wcstr, conv, locale);
367 mbstr[conv++] = '\0';
368 else if(conv==size && (count==MSVCRT__TRUNCATE || mbstr[conv-1]=='\0'))
369 mbstr[conv-1] = '\0';
371 MSVCRT_INVALID_PMT("mbstr[size] is too small");
374 *MSVCRT__errno() = MSVCRT_ERANGE;
375 return MSVCRT_ERANGE;
383 /*********************************************************************
384 * wcstombs_s (MSVCRT.@)
386 MSVCRT_size_t CDECL MSVCRT_wcstombs_s(MSVCRT_size_t *ret, char *mbstr,
387 MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr, MSVCRT_size_t count)
389 return MSVCRT__wcstombs_s_l(ret, mbstr, size, wcstr, count, NULL);
392 /*********************************************************************
395 double CDECL MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
397 return MSVCRT__wcstod_l(lpszStr, end, NULL);
400 /*********************************************************************
403 double CDECL MSVCRT__wtof(const MSVCRT_wchar_t *str)
405 return MSVCRT__wcstod_l(str, NULL, NULL);
408 /*********************************************************************
411 double CDECL MSVCRT__wtof_l(const MSVCRT_wchar_t *str, MSVCRT__locale_t locale)
413 return MSVCRT__wcstod_l(str, NULL, locale);
416 /*********************************************************************
417 * arg_clbk_valist (INTERNAL)
419 printf_arg arg_clbk_valist(void *ctx, int arg_pos, int type, __ms_va_list *valist)
424 ret.get_longlong = va_arg(*valist, LONGLONG);
425 else if(type == VT_INT)
426 ret.get_int = va_arg(*valist, int);
427 else if(type == VT_R8)
428 ret.get_double = va_arg(*valist, double);
429 else if(type == VT_PTR)
430 ret.get_ptr = va_arg(*valist, void*);
432 ERR("Incorrect type\n");
439 /*********************************************************************
440 * _vsnprintf (MSVCRT.@)
442 int CDECL MSVCRT_vsnprintf( char *str, MSVCRT_size_t len,
443 const char *format, __ms_va_list valist )
445 static const char nullbyte = '\0';
446 struct _str_ctx_a ctx = {len, str};
449 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, NULL, FALSE, FALSE,
450 arg_clbk_valist, NULL, valist);
451 puts_clbk_str_a(&ctx, 1, &nullbyte);
455 /*********************************************************************
456 * _vsnprintf_l (MSVCRT.@)
458 int CDECL MSVCRT_vsnprintf_l( char *str, MSVCRT_size_t len, const char *format,
459 MSVCRT__locale_t locale, __ms_va_list valist )
461 static const char nullbyte = '\0';
462 struct _str_ctx_a ctx = {len, str};
465 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, FALSE,
466 arg_clbk_valist, NULL, valist);
467 puts_clbk_str_a(&ctx, 1, &nullbyte);
471 /*********************************************************************
472 * _vsnprintf_s_l (MSVCRT.@)
474 int CDECL MSVCRT_vsnprintf_s_l( char *str, MSVCRT_size_t sizeOfBuffer,
475 MSVCRT_size_t count, const char *format,
476 MSVCRT__locale_t locale, __ms_va_list valist )
478 static const char nullbyte = '\0';
479 struct _str_ctx_a ctx;
482 if(sizeOfBuffer<count+1 || count==-1)
489 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, TRUE,
490 arg_clbk_valist, NULL, valist);
491 puts_clbk_str_a(&ctx, 1, &nullbyte);
493 if(ret<0 || ret==len) {
494 if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
495 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small");
496 *MSVCRT__errno() = MSVCRT_ERANGE;
497 memset(str, 0, sizeOfBuffer);
507 /*********************************************************************
508 * _vsnprintf_s (MSVCRT.@)
510 int CDECL MSVCRT_vsnprintf_s( char *str, MSVCRT_size_t sizeOfBuffer,
511 MSVCRT_size_t count, const char *format, __ms_va_list valist )
513 return MSVCRT_vsnprintf_s_l(str,sizeOfBuffer, count, format, NULL, valist);
516 /*********************************************************************
517 * vsprintf (MSVCRT.@)
519 int CDECL MSVCRT_vsprintf( char *str, const char *format, __ms_va_list valist)
521 return MSVCRT_vsnprintf(str, INT_MAX, format, valist);
524 /*********************************************************************
525 * vsprintf_s (MSVCRT.@)
527 int CDECL MSVCRT_vsprintf_s( char *str, MSVCRT_size_t num, const char *format, __ms_va_list valist)
529 return MSVCRT_vsnprintf(str, num, format, valist);
532 /*********************************************************************
533 * _vscprintf (MSVCRT.@)
535 int CDECL _vscprintf( const char *format, __ms_va_list valist )
537 return MSVCRT_vsnprintf( NULL, INT_MAX, format, valist );
540 /*********************************************************************
541 * _snprintf (MSVCRT.@)
543 int CDECL MSVCRT__snprintf(char *str, unsigned int len, const char *format, ...)
547 __ms_va_start(valist, format);
548 retval = MSVCRT_vsnprintf(str, len, format, valist);
553 /*********************************************************************
554 * _snprintf_s (MSVCRT.@)
556 int CDECL MSVCRT__snprintf_s(char *str, unsigned int len, unsigned int count,
557 const char *format, ...)
561 __ms_va_start(valist, format);
562 retval = MSVCRT_vsnprintf_s_l(str, len, count, format, NULL, valist);
567 /*********************************************************************
568 * _scprintf (MSVCRT.@)
570 int CDECL MSVCRT__scprintf(const char *format, ...)
574 __ms_va_start(valist, format);
575 retval = _vscprintf(format, valist);
580 /*********************************************************************
581 * _vsnwprintf (MSVCRT.@)
583 int CDECL MSVCRT_vsnwprintf(MSVCRT_wchar_t *str, MSVCRT_size_t len,
584 const MSVCRT_wchar_t *format, __ms_va_list valist)
586 static const MSVCRT_wchar_t nullbyte = '\0';
587 struct _str_ctx_w ctx = {len, str};
590 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, NULL, FALSE, FALSE,
591 arg_clbk_valist, NULL, valist);
592 puts_clbk_str_w(&ctx, 1, &nullbyte);
596 /*********************************************************************
597 * _vsnwprintf_l (MSVCRT.@)
599 int CDECL MSVCRT_vsnwprintf_l(MSVCRT_wchar_t *str, MSVCRT_size_t len,
600 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale,
603 static const MSVCRT_wchar_t nullbyte = '\0';
604 struct _str_ctx_w ctx = {len, str};
607 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, FALSE,
608 arg_clbk_valist, NULL, valist);
609 puts_clbk_str_w(&ctx, 1, &nullbyte);
613 /*********************************************************************
614 * _vsnwprintf_s_l (MSVCRT.@)
616 int CDECL MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
617 MSVCRT_size_t count, const MSVCRT_wchar_t *format,
618 MSVCRT__locale_t locale, __ms_va_list valist)
620 static const MSVCRT_wchar_t nullbyte = '\0';
621 struct _str_ctx_w ctx;
625 if(count!=-1 && len>count+1)
630 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, TRUE,
631 arg_clbk_valist, NULL, valist);
632 puts_clbk_str_w(&ctx, 1, &nullbyte);
634 if(ret<0 || ret==len) {
635 if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
636 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small");
637 *MSVCRT__errno() = MSVCRT_ERANGE;
638 memset(str, 0, sizeOfBuffer*sizeof(MSVCRT_wchar_t));
648 /*********************************************************************
649 * _vsnwprintf_s (MSVCRT.@)
651 int CDECL MSVCRT_vsnwprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
652 MSVCRT_size_t count, const MSVCRT_wchar_t *format, __ms_va_list valist)
654 return MSVCRT_vsnwprintf_s_l(str, sizeOfBuffer, count,
655 format, NULL, valist);
658 /*********************************************************************
659 * _snwprintf (MSVCRT.@)
661 int CDECL MSVCRT__snwprintf( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format, ...)
665 __ms_va_start(valist, format);
666 retval = MSVCRT_vsnwprintf(str, len, format, valist);
671 /*********************************************************************
672 * _snwprintf_s (MSVCRT.@)
674 int CDECL MSVCRT__snwprintf_s( MSVCRT_wchar_t *str, unsigned int len, unsigned int count,
675 const MSVCRT_wchar_t *format, ...)
679 __ms_va_start(valist, format);
680 retval = MSVCRT_vsnwprintf_s_l(str, len, count, format, NULL, valist);
685 /*********************************************************************
688 int CDECL MSVCRT_sprintf( char *str, const char *format, ... )
693 __ms_va_start( ap, format );
694 r = MSVCRT_vsnprintf( str, INT_MAX, format, ap );
699 /*********************************************************************
700 * sprintf_s (MSVCRT.@)
702 int CDECL MSVCRT_sprintf_s( char *str, MSVCRT_size_t num, const char *format, ... )
707 __ms_va_start( ap, format );
708 r = MSVCRT_vsnprintf( str, num, format, ap );
713 /*********************************************************************
714 * _scwprintf (MSVCRT.@)
716 int CDECL MSVCRT__scwprintf( const MSVCRT_wchar_t *format, ... )
721 __ms_va_start( ap, format );
722 r = MSVCRT_vsnwprintf( NULL, INT_MAX, format, ap );
727 /*********************************************************************
728 * swprintf (MSVCRT.@)
730 int CDECL MSVCRT_swprintf( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ... )
735 __ms_va_start( ap, format );
736 r = MSVCRT_vsnwprintf( str, INT_MAX, format, ap );
741 /*********************************************************************
742 * swprintf_s (MSVCRT.@)
744 int CDECL MSVCRT_swprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t numberOfElements,
745 const MSVCRT_wchar_t *format, ... )
750 __ms_va_start(ap, format);
751 r = MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, ap);
757 /*********************************************************************
758 * vswprintf (MSVCRT.@)
760 int CDECL MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, __ms_va_list args )
762 return MSVCRT_vsnwprintf( str, INT_MAX, format, args );
765 /*********************************************************************
766 * _vscwprintf (MSVCRT.@)
768 int CDECL _vscwprintf( const MSVCRT_wchar_t *format, __ms_va_list args )
770 return MSVCRT_vsnwprintf( NULL, INT_MAX, format, args );
773 /*********************************************************************
774 * vswprintf_s (MSVCRT.@)
776 int CDECL MSVCRT_vswprintf_s(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
777 const MSVCRT_wchar_t* format, __ms_va_list args)
779 return MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, args );
782 /*********************************************************************
783 * _vswprintf_s_l (MSVCRT.@)
785 int CDECL MSVCRT_vswprintf_s_l(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
786 const MSVCRT_wchar_t* format, MSVCRT__locale_t locale, __ms_va_list args)
788 return MSVCRT_vsnwprintf_s_l(str, numberOfElements, INT_MAX,
789 format, locale, args );
792 /*********************************************************************
795 int CDECL MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
797 /* FIXME: handle collates */
798 return strcmpW( str1, str2 );
801 /*********************************************************************
804 MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
806 const MSVCRT_wchar_t* p;
809 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
815 /*********************************************************************
816 * wcstok_s (MSVCRT.@)
818 MSVCRT_wchar_t * CDECL wcstok_s( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim,
819 MSVCRT_wchar_t **next_token )
823 if (!MSVCRT_CHECK_PMT(delim != NULL) || !MSVCRT_CHECK_PMT(next_token != NULL) ||
824 !MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL))
826 *MSVCRT__errno() = MSVCRT_EINVAL;
829 if (!str) str = *next_token;
831 while (*str && strchrW( delim, *str )) str++;
832 if (!*str) return NULL;
834 while (*str && !strchrW( delim, *str )) str++;
835 if (*str) *str++ = 0;
840 /*********************************************************************
843 MSVCRT_wchar_t * CDECL MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
845 return wcstok_s(str, delim, &msvcrt_get_thread_data()->wcstok_next);
848 /*********************************************************************
851 INT CDECL MSVCRT_wctob( MSVCRT_wint_t wchar )
853 MSVCRT__locale_t locale = get_locale();
857 if(WideCharToMultiByte( locale->locinfo->lc_codepage, 0, &wchar, 1, &out, 1, NULL, &error ) && !error)
862 /*********************************************************************
865 INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
867 MSVCRT__locale_t locale = get_locale();
868 return WideCharToMultiByte( locale->locinfo->lc_codepage, 0, &ch, 1, dst, 6, NULL, NULL );
871 /*********************************************************************
872 * iswalnum (MSVCRT.@)
874 INT CDECL MSVCRT_iswalnum( MSVCRT_wchar_t wc )
876 return isalnumW( wc );
879 /*********************************************************************
880 * iswalpha (MSVCRT.@)
882 INT CDECL MSVCRT_iswalpha( MSVCRT_wchar_t wc )
884 return isalphaW( wc );
887 /*********************************************************************
888 * iswalpha_l (MSVCRT.@)
890 INT CDECL MSVCRT__iswalpha_l( MSVCRT_wchar_t wc, MSVCRT__locale_t locale )
892 return isalphaW( wc );
895 /*********************************************************************
896 * iswcntrl (MSVCRT.@)
898 INT CDECL MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
900 return iscntrlW( wc );
903 /*********************************************************************
904 * iswdigit (MSVCRT.@)
906 INT CDECL MSVCRT_iswdigit( MSVCRT_wchar_t wc )
908 return isdigitW( wc );
911 /*********************************************************************
912 * iswgraph (MSVCRT.@)
914 INT CDECL MSVCRT_iswgraph( MSVCRT_wchar_t wc )
916 return isgraphW( wc );
919 /*********************************************************************
920 * iswlower (MSVCRT.@)
922 INT CDECL MSVCRT_iswlower( MSVCRT_wchar_t wc )
924 return islowerW( wc );
927 /*********************************************************************
928 * iswprint (MSVCRT.@)
930 INT CDECL MSVCRT_iswprint( MSVCRT_wchar_t wc )
932 return isprintW( wc );
935 /*********************************************************************
936 * iswpunct (MSVCRT.@)
938 INT CDECL MSVCRT_iswpunct( MSVCRT_wchar_t wc )
940 return ispunctW( wc );
943 /*********************************************************************
944 * iswspace (MSVCRT.@)
946 INT CDECL MSVCRT_iswspace( MSVCRT_wchar_t wc )
948 return isspaceW( wc );
951 /*********************************************************************
952 * iswupper (MSVCRT.@)
954 INT CDECL MSVCRT_iswupper( MSVCRT_wchar_t wc )
956 return isupperW( wc );
959 /*********************************************************************
960 * iswxdigit (MSVCRT.@)
962 INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
964 return isxdigitW( wc );
967 /*********************************************************************
968 * wcscpy_s (MSVCRT.@)
970 INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc)
972 MSVCRT_size_t size = 0;
974 if(!wcDest || !numElement)
975 return MSVCRT_EINVAL;
981 return MSVCRT_EINVAL;
984 size = strlenW(wcSrc) + 1;
986 if(size > numElement)
988 return MSVCRT_ERANGE;
991 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
996 /******************************************************************
997 * wcsncpy_s (MSVCRT.@)
999 INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc,
1000 MSVCRT_size_t count )
1002 MSVCRT_size_t size = 0;
1004 if (!wcDest || !numElement)
1005 return MSVCRT_EINVAL;
1011 return MSVCRT_EINVAL;
1014 size = min(strlenW(wcSrc), count);
1016 if (size >= numElement)
1018 return MSVCRT_ERANGE;
1021 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
1022 wcDest[size] = '\0';
1027 /******************************************************************
1028 * wcscat_s (MSVCRT.@)
1031 INT CDECL MSVCRT_wcscat_s(MSVCRT_wchar_t* dst, MSVCRT_size_t elem, const MSVCRT_wchar_t* src)
1033 MSVCRT_wchar_t* ptr = dst;
1035 if (!dst || elem == 0) return MSVCRT_EINVAL;
1039 return MSVCRT_EINVAL;
1042 /* seek to end of dst string (or elem if no end of string is found */
1043 while (ptr < dst + elem && *ptr != '\0') ptr++;
1044 while (ptr < dst + elem)
1046 if ((*ptr++ = *src++) == '\0') return 0;
1048 /* not enough space */
1050 return MSVCRT_ERANGE;
1053 /*********************************************************************
1054 * wcsncat_s (MSVCRT.@)
1057 INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
1058 const MSVCRT_wchar_t *src, MSVCRT_size_t count)
1060 MSVCRT_size_t srclen;
1061 MSVCRT_wchar_t dststart;
1064 if (!MSVCRT_CHECK_PMT(dst != NULL) || !MSVCRT_CHECK_PMT(elem > 0))
1066 *MSVCRT__errno() = MSVCRT_EINVAL;
1067 return MSVCRT_EINVAL;
1069 if (!MSVCRT_CHECK_PMT(src != NULL || count == 0))
1070 return MSVCRT_EINVAL;
1074 for (dststart = 0; dststart < elem; dststart++)
1076 if (dst[dststart] == '\0')
1079 if (dststart == elem)
1081 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n");
1082 return MSVCRT_EINVAL;
1085 if (count == MSVCRT__TRUNCATE)
1087 srclen = strlenW(src);
1088 if (srclen >= (elem - dststart))
1090 srclen = elem - dststart - 1;
1091 ret = MSVCRT_STRUNCATE;
1095 srclen = min(strlenW(src), count);
1096 if (srclen < (elem - dststart))
1098 memcpy(&dst[dststart], src, srclen*sizeof(MSVCRT_wchar_t));
1099 dst[dststart+srclen] = '\0';
1102 MSVCRT_INVALID_PMT("dst[elem] is too small");
1104 return MSVCRT_ERANGE;
1107 /*********************************************************************
1108 * _wcstoi64_l (MSVCRT.@)
1110 * FIXME: locale parameter is ignored
1112 __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
1113 MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
1115 BOOL negative = FALSE;
1118 TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
1120 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
1121 !MSVCRT_CHECK_PMT(base <= 36)) {
1122 *MSVCRT__errno() = MSVCRT_EINVAL;
1126 while(isspaceW(*nptr)) nptr++;
1131 } else if(*nptr == '+')
1134 if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
1147 char cur = tolowerW(*nptr);
1155 if(cur<'a' || cur>='a'+base-10)
1165 if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
1166 ret = MSVCRT_I64_MAX;
1167 *MSVCRT__errno() = MSVCRT_ERANGE;
1168 } else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
1169 ret = MSVCRT_I64_MIN;
1170 *MSVCRT__errno() = MSVCRT_ERANGE;
1176 *endptr = (MSVCRT_wchar_t*)nptr;
1181 /*********************************************************************
1182 * _wcstoi64 (MSVCRT.@)
1184 __int64 CDECL MSVCRT__wcstoi64(const MSVCRT_wchar_t *nptr,
1185 MSVCRT_wchar_t **endptr, int base)
1187 return MSVCRT__wcstoi64_l(nptr, endptr, base, NULL);
1190 /*********************************************************************
1191 * _wcstoui64_l (MSVCRT.@)
1193 * FIXME: locale parameter is ignored
1195 unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
1196 MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
1198 BOOL negative = FALSE;
1199 unsigned __int64 ret = 0;
1201 TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
1203 if (!MSVCRT_CHECK_PMT(nptr != NULL) || !MSVCRT_CHECK_PMT(base == 0 || base >= 2) ||
1204 !MSVCRT_CHECK_PMT(base <= 36)) {
1205 *MSVCRT__errno() = MSVCRT_EINVAL;
1209 while(isspaceW(*nptr)) nptr++;
1214 } else if(*nptr == '+')
1217 if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
1230 char cur = tolowerW(*nptr);
1238 if(cur<'a' || cur>='a'+base-10)
1245 if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
1246 ret = MSVCRT_UI64_MAX;
1247 *MSVCRT__errno() = MSVCRT_ERANGE;
1253 *endptr = (MSVCRT_wchar_t*)nptr;
1255 return negative ? -ret : ret;
1258 /*********************************************************************
1259 * _wcstoui64 (MSVCRT.@)
1261 unsigned __int64 CDECL MSVCRT__wcstoui64(const MSVCRT_wchar_t *nptr,
1262 MSVCRT_wchar_t **endptr, int base)
1264 return MSVCRT__wcstoui64_l(nptr, endptr, base, NULL);
1267 /******************************************************************
1268 * wcsnlen (MSVCRT.@)
1270 MSVCRT_size_t CDECL MSVCRT_wcsnlen(const MSVCRT_wchar_t *s, MSVCRT_size_t maxlen)
1274 for (i = 0; i < maxlen; i++)