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
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
33 /*********************************************************************
36 MSVCRT_wchar_t* CDECL _wcsdup( const MSVCRT_wchar_t* str )
38 MSVCRT_wchar_t* ret = NULL;
41 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
42 ret = MSVCRT_malloc( size );
43 if (ret) memcpy( ret, str, size );
48 /*********************************************************************
49 * _wcsicoll (MSVCRT.@)
51 INT CDECL _wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
53 /* FIXME: handle collates */
54 return strcmpiW( str1, str2 );
57 /*********************************************************************
60 MSVCRT_wchar_t* CDECL _wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
62 MSVCRT_wchar_t* ret = str;
63 while ((n-- > 0) && *str) *str++ = c;
67 /*********************************************************************
70 MSVCRT_wchar_t* CDECL _wcsrev( MSVCRT_wchar_t* str )
72 MSVCRT_wchar_t* ret = str;
73 MSVCRT_wchar_t* end = str + strlenW(str) - 1;
76 MSVCRT_wchar_t t = *end;
83 /*********************************************************************
86 MSVCRT_wchar_t* CDECL _wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
88 MSVCRT_wchar_t* ret = str;
89 while (*str) *str++ = c;
93 /******************************************************************
94 * _wcsupr_s (MSVCRT.@)
97 INT CDECL MSVCRT__wcsupr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
99 MSVCRT_wchar_t* ptr = str;
103 if (str) *str = '\0';
104 *MSVCRT__errno() = MSVCRT_EINVAL;
105 return MSVCRT_EINVAL;
111 *ptr = toupperW(*ptr);
115 /* MSDN claims that the function should return and set errno to
116 * ERANGE, which doesn't seem to be true based on the tests. */
118 *MSVCRT__errno() = MSVCRT_EINVAL;
119 return MSVCRT_EINVAL;
122 /*********************************************************************
125 double CDECL MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
127 const MSVCRT_wchar_t* str = lpszStr;
129 double ret = 0, divisor = 10.0;
131 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end);
134 * - Should set errno on failure
135 * - Should fail on overflow
136 * - Need to check which input formats are allowed
138 while (isspaceW(*str))
147 while (isdigitW(*str))
149 ret = ret * 10.0 + (*str - '0');
154 while (isdigitW(*str))
156 ret = ret + (*str - '0') / divisor;
161 if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd')
163 int negativeExponent = 0;
167 negativeExponent = 1;
170 while (isdigitW(*str))
172 exponent = exponent * 10 + (*str - '0');
177 if (negativeExponent)
178 ret = ret / pow(10.0, exponent);
180 ret = ret * pow(10.0, exponent);
188 *end = (MSVCRT_wchar_t*)str;
190 TRACE("returning %g\n", ret);
195 typedef struct pf_output_t
206 typedef struct pf_flags_t
208 char Sign, LeftAlign, Alternate, PadZero;
209 int FieldLength, Precision;
210 char IntegerLength, IntegerDouble;
216 * writes a string of characters to the output
217 * returns -1 if the string doesn't fit in the output buffer
218 * return the length of the string if all characters were written
220 static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
222 int space = out->len - out->used;
225 len = strlenW( str );
228 LPWSTR p = out->buf.W + out->used;
232 if (out->buf.W) memcpy( p, str, len*sizeof(WCHAR) );
236 if( space > 0 && out->buf.W )
237 memcpy( p, str, space*sizeof(WCHAR) );
242 int n = WideCharToMultiByte( CP_ACP, 0, str, len, NULL, 0, NULL, NULL );
243 LPSTR p = out->buf.A + out->used;
247 if (out->buf.A) WideCharToMultiByte( CP_ACP, 0, str, len, p, n, NULL, NULL );
251 if( space > 0 && out->buf.A )
252 WideCharToMultiByte( CP_ACP, 0, str, len, p, space, NULL, NULL );
258 static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
260 int space = out->len - out->used;
266 LPSTR p = out->buf.A + out->used;
270 if (out->buf.A) memcpy( p, str, len );
274 if( space > 0 && out->buf.A )
275 memcpy( p, str, space );
280 int n = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 );
281 LPWSTR p = out->buf.W + out->used;
285 if (out->buf.W) MultiByteToWideChar( CP_ACP, 0, str, len, p, n );
289 if( space > 0 && out->buf.W )
290 MultiByteToWideChar( CP_ACP, 0, str, len, p, space );
296 /* pf_fill: takes care of signs, alignment, zero and field padding */
297 static inline int pf_fill( pf_output *out, int len, pf_flags *flags, char left )
301 if( flags->Sign && !( flags->Format == 'd' || flags->Format == 'i' ) )
304 if( left && flags->Sign )
306 flags->FieldLength--;
308 r = pf_output_stringA( out, &flags->Sign, 1 );
311 if( ( !left && flags->LeftAlign ) ||
312 ( left && !flags->LeftAlign ))
314 for( i=0; (i<(flags->FieldLength-len)) && (r>=0); i++ )
316 if( left && flags->PadZero )
317 r = pf_output_stringA( out, "0", 1 );
319 r = pf_output_stringA( out, " ", 1 );
323 if( left && flags->Sign && !flags->PadZero )
324 r = pf_output_stringA( out, &flags->Sign, 1 );
329 static inline int pf_output_format_W( pf_output *out, LPCWSTR str,
330 int len, pf_flags *flags )
335 len = strlenW( str );
337 if (flags->Precision >= 0 && flags->Precision < len)
338 len = flags->Precision;
340 r = pf_fill( out, len, flags, 1 );
343 r = pf_output_stringW( out, str, len );
346 r = pf_fill( out, len, flags, 0 );
351 static inline int pf_output_format_A( pf_output *out, LPCSTR str,
352 int len, pf_flags *flags )
359 if (flags->Precision >= 0 && flags->Precision < len)
360 len = flags->Precision;
362 r = pf_fill( out, len, flags, 1 );
365 r = pf_output_stringA( out, str, len );
368 r = pf_fill( out, len, flags, 0 );
373 static int pf_handle_string_format( pf_output *out, const void* str, int len,
374 pf_flags *flags, BOOL capital_letter)
376 if(str == NULL) /* catch NULL pointer */
377 return pf_output_format_A( out, "(null)", -1, flags);
379 /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */
380 if(flags->WideString || flags->IntegerLength == 'l')
381 return pf_output_format_W( out, str, len, flags);
382 if(flags->IntegerLength == 'h')
383 return pf_output_format_A( out, str, len, flags);
385 /* %s,%c -> chars in ansi functions & wchars in unicode
386 * %S,%C -> wchars in ansi functions & chars in unicode */
387 if( capital_letter == out->unicode) /* either both TRUE or both FALSE */
388 return pf_output_format_A( out, str, len, flags);
390 return pf_output_format_W( out, str, len, flags);
393 static inline BOOL pf_is_integer_format( char fmt )
395 static const char float_fmts[] = "diouxX";
398 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
401 static inline BOOL pf_is_double_format( char fmt )
403 static const char float_fmts[] = "aeEfgG";
406 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
409 static inline BOOL pf_is_valid_format( char fmt )
411 static const char float_fmts[] = "acCdeEfgGinouxX";
414 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
417 static void pf_rebuild_format_string( char *p, pf_flags *flags )
422 if( flags->LeftAlign )
423 *p++ = flags->LeftAlign;
424 if( flags->Alternate )
425 *p++ = flags->Alternate;
427 *p++ = flags->PadZero;
428 if( flags->FieldLength )
430 sprintf(p, "%d", flags->FieldLength);
433 if( flags->Precision >= 0 )
435 sprintf(p, ".%d", flags->Precision);
438 *p++ = flags->Format;
442 /* pf_integer_conv: prints x to buf, including alternate formats and
443 additional precision digits, but not field characters or the sign */
444 static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags,
451 char number[40], *tmp = number;
453 if( buf_len > sizeof number )
454 tmp = HeapAlloc( GetProcessHeap(), 0, buf_len );
457 if( flags->Format == 'o' )
459 else if( flags->Format == 'x' || flags->Format == 'X' )
462 if( flags->Format == 'X' )
463 digits = "0123456789ABCDEFX";
465 digits = "0123456789abcdefx";
467 if( x < 0 && ( flags->Format == 'd' || flags->Format == 'i' ) )
473 /* Do conversion (backwards) */
475 if( x == 0 && flags->Precision )
480 j = (ULONGLONG) x % base;
481 x = (ULONGLONG) x / base;
482 tmp[i++] = digits[j];
484 k = flags->Precision - i;
487 if( flags->Alternate )
491 tmp[i++] = digits[16];
494 else if( base == 8 && tmp[i-1] != '0' )
498 /* Reverse for buf */
504 /* Adjust precision so pf_fill won't truncate the number later */
505 flags->Precision = strlen( buf );
508 HeapFree( GetProcessHeap(), 0, tmp );
513 /* pf_fixup_exponent: convert a string containing a 2 digit exponent
514 to 3 digits, accounting for padding, in place. Needed to match
515 the native printf's which always use 3 digits. */
516 static void pf_fixup_exponent( char *buf )
520 while (tmp[0] && toupper(tmp[0]) != 'E')
523 if (tmp[0] && (tmp[1] == '+' || tmp[1] == '-') &&
524 isdigit(tmp[2]) && isdigit(tmp[3]))
529 return; /* Exponent already 3 digits */
531 /* We have a 2 digit exponent. Prepend '0' to make it 3 */
539 /* We didn't expand into trailing space, so this string isn't left
540 * justified. Terminate the string and strip a ' ' at the start of
541 * the string if there is one (as there may be if the string is
546 memmove(buf, buf + 1, (tmp - buf) + 3);
548 /* Otherwise, we expanded into trailing space -> nothing to do */
552 /*********************************************************************
553 * pf_vsnprintf (INTERNAL)
555 * implements both A and W vsnprintf functions
557 static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valist )
560 LPCWSTR q, p = format;
563 TRACE("format is %s\n",debugstr_w(format));
566 q = strchrW( p, '%' );
568 /* there's no % characters left, output the rest of the string */
571 r = pf_output_stringW(out, p, -1);
578 /* there's characters before the %, output them */
581 r = pf_output_stringW(out, p, q - p);
587 /* we must be at a % now, skip over it */
591 /* output a single % character */
594 r = pf_output_stringW(out, p++, 1);
600 /* parse the flags */
601 memset( &flags, 0, sizeof flags );
604 if( *p == '+' || *p == ' ' )
606 if ( flags.Sign != '+' )
610 flags.LeftAlign = *p;
614 flags.Alternate = *p;
620 /* deal with the field width specifier */
621 flags.FieldLength = 0;
624 flags.FieldLength = va_arg( valist, int );
625 if (flags.FieldLength < 0)
627 flags.LeftAlign = '-';
628 flags.FieldLength = -flags.FieldLength;
632 else while( isdigit(*p) )
634 flags.FieldLength *= 10;
635 flags.FieldLength += *p++ - '0';
638 /* deal with precision */
639 flags.Precision = -1;
646 flags.Precision = va_arg( valist, int );
649 else while( isdigit(*p) )
651 flags.Precision *= 10;
652 flags.Precision += *p++ - '0';
656 /* deal with integer width modifier */
659 if( *p == 'h' || *p == 'l' || *p == 'L' )
661 flags.IntegerLength = *p;
666 if( *(p+1) == '6' && *(p+2) == '4' )
668 flags.IntegerDouble++;
671 else if( *(p+1) == '3' && *(p+2) == '2' )
673 else if( isdigit(*(p+1)) || *(p+1) == 0 )
679 flags.WideString = *p++;
689 if (flags.Format == '$')
691 FIXME("Positional parameters are not supported (%s)\n", wine_dbgstr_w(format));
694 /* output a string */
695 if( flags.Format == 's' || flags.Format == 'S' )
696 r = pf_handle_string_format( out, va_arg(valist, const void*), -1,
697 &flags, (flags.Format == 'S') );
699 /* output a single character */
700 else if( flags.Format == 'c' || flags.Format == 'C' )
702 INT ch = va_arg( valist, int );
704 r = pf_handle_string_format( out, &ch, 1, &flags, (flags.Format == 'C') );
707 /* output a pointer */
708 else if( flags.Format == 'p' )
711 void *ptr = va_arg( valist, void * );
714 if( flags.Alternate )
715 sprintf(pointer, "0X%0*lX", 2 * (int)sizeof(ptr), (ULONG_PTR)ptr);
717 sprintf(pointer, "%0*lX", 2 * (int)sizeof(ptr), (ULONG_PTR)ptr);
718 r = pf_output_format_A( out, pointer, -1, &flags );
722 else if( flags.Format == 'n' )
724 int *x = va_arg(valist, int *);
728 /* deal with 64-bit integers */
729 else if( pf_is_integer_format( flags.Format ) && flags.IntegerDouble )
731 char number[40], *x = number;
733 /* Estimate largest possible required buffer size:
734 * Chooses the larger of the field or precision
735 * Includes extra bytes: 1 byte for null, 1 byte for sign,
736 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
737 for a decimal, and 1 byte for an additional float digit. */
738 int x_len = ((flags.FieldLength > flags.Precision) ?
739 flags.FieldLength : flags.Precision) + 10;
741 if( x_len >= sizeof number)
742 x = HeapAlloc( GetProcessHeap(), 0, x_len );
744 pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) );
746 r = pf_output_format_A( out, x, -1, &flags );
748 HeapFree( GetProcessHeap(), 0, x );
751 /* deal with integers and floats using libc's printf */
752 else if( pf_is_valid_format( flags.Format ) )
754 char fmt[20], number[40], *x = number;
756 /* Estimate largest possible required buffer size:
757 * Chooses the larger of the field or precision
758 * Includes extra bytes: 1 byte for null, 1 byte for sign,
759 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
760 for a decimal, and 1 byte for an additional float digit. */
761 int x_len = ((flags.FieldLength > flags.Precision) ?
762 flags.FieldLength : flags.Precision) + 10;
764 if( x_len >= sizeof number)
765 x = HeapAlloc( GetProcessHeap(), 0, x_len );
767 pf_rebuild_format_string( fmt, &flags );
769 if( pf_is_double_format( flags.Format ) )
771 sprintf( x, fmt, va_arg(valist, double) );
772 if (toupper(flags.Format) == 'E' || toupper(flags.Format) == 'G')
773 pf_fixup_exponent( x );
776 sprintf( x, fmt, va_arg(valist, int) );
778 r = pf_output_stringA( out, x, -1 );
780 HeapFree( GetProcessHeap(), 0, x );
790 /* check we reached the end, and null terminate the string */
792 pf_output_stringW( out, p, 1 );
794 return out->used - 1;
797 /*********************************************************************
798 * _vsnprintf (MSVCRT.@)
800 int CDECL MSVCRT_vsnprintf( char *str, unsigned int len,
801 const char *format, __ms_va_list valist )
804 LPWSTR formatW = NULL;
813 sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 );
814 formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
815 MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz );
817 r = pf_vsnprintf( &out, formatW, valist );
819 HeapFree( GetProcessHeap(), 0, formatW );
824 /*********************************************************************
825 * vsprintf (MSVCRT.@)
827 int CDECL MSVCRT_vsprintf( char *str, const char *format, __ms_va_list valist)
829 return MSVCRT_vsnprintf(str, INT_MAX, format, valist);
832 /*********************************************************************
833 * _vscprintf (MSVCRT.@)
835 int CDECL _vscprintf( const char *format, __ms_va_list valist )
837 return MSVCRT_vsnprintf( NULL, INT_MAX, format, valist );
840 /*********************************************************************
841 * _snprintf (MSVCRT.@)
843 int CDECL MSVCRT__snprintf(char *str, unsigned int len, const char *format, ...)
847 __ms_va_start(valist, format);
848 retval = MSVCRT_vsnprintf(str, len, format, valist);
853 /*********************************************************************
854 * _vsnwsprintf (MSVCRT.@)
856 int CDECL MSVCRT_vsnwprintf( MSVCRT_wchar_t *str, unsigned int len,
857 const MSVCRT_wchar_t *format, __ms_va_list valist )
866 return pf_vsnprintf( &out, format, valist );
869 /*********************************************************************
870 * _snwprintf (MSVCRT.@)
872 int CDECL MSVCRT__snwprintf( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format, ...)
876 __ms_va_start(valist, format);
877 retval = MSVCRT_vsnwprintf(str, len, format, valist);
882 /*********************************************************************
885 int CDECL MSVCRT_sprintf( char *str, const char *format, ... )
890 __ms_va_start( ap, format );
891 r = MSVCRT_vsnprintf( str, INT_MAX, format, ap );
896 /*********************************************************************
897 * swprintf (MSVCRT.@)
899 int CDECL MSVCRT_swprintf( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ... )
904 __ms_va_start( ap, format );
905 r = MSVCRT_vsnwprintf( str, INT_MAX, format, ap );
910 /*********************************************************************
911 * vswprintf (MSVCRT.@)
913 int CDECL MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, __ms_va_list args )
915 return MSVCRT_vsnwprintf( str, INT_MAX, format, args );
918 /*********************************************************************
919 * _vscwprintf (MSVCRT.@)
921 int CDECL _vscwprintf( const MSVCRT_wchar_t *format, __ms_va_list args )
923 return MSVCRT_vsnwprintf( NULL, INT_MAX, format, args );
926 /*********************************************************************
927 * vswprintf_s (MSVCRT.@)
929 int CDECL MSVCRT_vswprintf_s( MSVCRT_wchar_t* str, MSVCRT_size_t num, const MSVCRT_wchar_t* format, __ms_va_list args )
931 /* FIXME: must handle positional arguments */
932 return MSVCRT_vsnwprintf( str, num, format, args );
935 /*********************************************************************
938 int CDECL MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
940 /* FIXME: handle collates */
941 return strcmpW( str1, str2 );
944 /*********************************************************************
947 MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
949 const MSVCRT_wchar_t* p;
952 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
958 /*********************************************************************
961 MSVCRT_wchar_t * CDECL MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
963 thread_data_t *data = msvcrt_get_thread_data();
967 if (!(str = data->wcstok_next)) return NULL;
969 while (*str && strchrW( delim, *str )) str++;
970 if (!*str) return NULL;
972 while (*str && !strchrW( delim, *str )) str++;
973 if (*str) *str++ = 0;
974 data->wcstok_next = str;
979 /*********************************************************************
982 INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
984 return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
987 /*********************************************************************
988 * iswalnum (MSVCRT.@)
990 INT CDECL MSVCRT_iswalnum( MSVCRT_wchar_t wc )
992 return isalnumW( wc );
995 /*********************************************************************
996 * iswalpha (MSVCRT.@)
998 INT CDECL MSVCRT_iswalpha( MSVCRT_wchar_t wc )
1000 return isalphaW( wc );
1003 /*********************************************************************
1004 * iswcntrl (MSVCRT.@)
1006 INT CDECL MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
1008 return iscntrlW( wc );
1011 /*********************************************************************
1012 * iswdigit (MSVCRT.@)
1014 INT CDECL MSVCRT_iswdigit( MSVCRT_wchar_t wc )
1016 return isdigitW( wc );
1019 /*********************************************************************
1020 * iswgraph (MSVCRT.@)
1022 INT CDECL MSVCRT_iswgraph( MSVCRT_wchar_t wc )
1024 return isgraphW( wc );
1027 /*********************************************************************
1028 * iswlower (MSVCRT.@)
1030 INT CDECL MSVCRT_iswlower( MSVCRT_wchar_t wc )
1032 return islowerW( wc );
1035 /*********************************************************************
1036 * iswprint (MSVCRT.@)
1038 INT CDECL MSVCRT_iswprint( MSVCRT_wchar_t wc )
1040 return isprintW( wc );
1043 /*********************************************************************
1044 * iswpunct (MSVCRT.@)
1046 INT CDECL MSVCRT_iswpunct( MSVCRT_wchar_t wc )
1048 return ispunctW( wc );
1051 /*********************************************************************
1052 * iswspace (MSVCRT.@)
1054 INT CDECL MSVCRT_iswspace( MSVCRT_wchar_t wc )
1056 return isspaceW( wc );
1059 /*********************************************************************
1060 * iswupper (MSVCRT.@)
1062 INT CDECL MSVCRT_iswupper( MSVCRT_wchar_t wc )
1064 return isupperW( wc );
1067 /*********************************************************************
1068 * iswxdigit (MSVCRT.@)
1070 INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
1072 return isxdigitW( wc );
1075 /*********************************************************************
1076 * wcscpy_s (MSVCRT.@)
1078 INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc)
1080 MSVCRT_size_t size = 0;
1082 if(!wcDest || !numElement)
1083 return MSVCRT_EINVAL;
1089 return MSVCRT_EINVAL;
1092 size = strlenW(wcSrc) + 1;
1094 if(size > numElement)
1096 return MSVCRT_ERANGE;
1099 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
1104 /******************************************************************
1105 * wcsncpy_s (MSVCRT.@)
1107 INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc,
1108 MSVCRT_size_t count )
1110 MSVCRT_size_t size = 0;
1112 if (!wcDest || !numElement)
1113 return MSVCRT_EINVAL;
1119 return MSVCRT_EINVAL;
1122 size = min(strlenW(wcSrc), count);
1124 if (size >= numElement)
1126 return MSVCRT_ERANGE;
1129 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
1130 wcDest[size] = '\0';
1135 /******************************************************************
1136 * wcscat_s (MSVCRT.@)
1139 INT CDECL MSVCRT_wcscat_s(MSVCRT_wchar_t* dst, MSVCRT_size_t elem, const MSVCRT_wchar_t* src)
1141 MSVCRT_wchar_t* ptr = dst;
1143 if (!dst || elem == 0) return MSVCRT_EINVAL;
1147 return MSVCRT_EINVAL;
1150 /* seek to end of dst string (or elem if no end of string is found */
1151 while (ptr < dst + elem && *ptr != '\0') ptr++;
1152 while (ptr < dst + elem)
1154 if ((*ptr++ = *src++) == '\0') return 0;
1156 /* not enough space */
1158 return MSVCRT_ERANGE;