2 * PROJECT: ReactOS CRT library
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: lib/sdk/crt/string/wcs.c
5 * PURPOSE: wcs* CRT functions
6 * PROGRAMMERS: Wine team
7 * Ported to ReactOS by Aleksey Bragin (aleksey@reactos.org)
11 * msvcrt.dll wide-char functions
13 * Copyright 1999 Alexandre Julliard
14 * Copyright 2000 Jon Griffiths
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include <internal/wine/msvcrt.h>
37 #include "wine/unicode.h"
38 //#include "wine/debug.h"
41 //WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
51 /*********************************************************************
54 wchar_t* CDECL
_wcsdup( const wchar_t* str
)
59 int size
= (strlenW(str
) + 1) * sizeof(wchar_t);
61 if (ret
) memcpy( ret
, str
, size
);
65 /*********************************************************************
66 * _wcsicoll (MSVCRT.@)
68 INT CDECL
_wcsicoll( const wchar_t* str1
, const wchar_t* str2
)
70 /* FIXME: handle collates */
71 return strcmpiW( str1
, str2
);
75 /*********************************************************************
78 wchar_t* CDECL
_wcsnset( wchar_t* str
, wchar_t c
, size_t n
)
81 while ((n
-- > 0) && *str
) *str
++ = c
;
85 /*********************************************************************
88 wchar_t* CDECL
_wcsrev( wchar_t* str
)
91 wchar_t* end
= str
+ strlenW(str
) - 1;
102 /*********************************************************************
105 wchar_t* CDECL
_wcsset( wchar_t* str
, wchar_t c
)
108 while (*str
) *str
++ = c
;
112 /******************************************************************
113 * _wcsupr_s (MSVCRT.@)
116 INT CDECL
_wcsupr_s( wchar_t* str
, size_t n
)
122 if (str
) *str
= '\0';
130 *ptr
= toupperW(*ptr
);
134 /* MSDN claims that the function should return and set errno to
135 * ERANGE, which doesn't seem to be true based on the tests. */
141 /*********************************************************************
144 double CDECL
wcstod(const wchar_t* lpszStr
, wchar_t** end
)
146 const wchar_t* str
= lpszStr
;
148 double ret
= 0, divisor
= 10.0;
150 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr
), end
);
153 * - Should set errno on failure
154 * - Should fail on overflow
155 * - Need to check which input formats are allowed
157 while (isspaceW(*str
))
166 while (isdigitW(*str
))
168 ret
= ret
* 10.0 + (*str
- '0');
173 while (isdigitW(*str
))
175 ret
= ret
+ (*str
- '0') / divisor
;
180 if (*str
== 'E' || *str
== 'e' || *str
== 'D' || *str
== 'd')
182 int negativeExponent
= 0;
186 negativeExponent
= 1;
189 while (isdigitW(*str
))
191 exponent
= exponent
* 10 + (*str
- '0');
196 if (negativeExponent
)
197 ret
= ret
/ pow(10.0, exponent
);
199 ret
= ret
* pow(10.0, exponent
);
207 *end
= (wchar_t*)str
;
209 TRACE("returning %g\n", ret
);
213 typedef struct pf_output_t
224 typedef struct pf_flags_t
226 char Sign
, LeftAlign
, Alternate
, PadZero
;
227 int FieldLength
, Precision
;
228 char IntegerLength
, IntegerDouble
;
234 * writes a string of characters to the output
235 * returns -1 if the string doesn't fit in the output buffer
236 * return the length of the string if all characters were written
238 static inline int pf_output_stringW( pf_output
*out
, LPCWSTR str
, int len
)
240 int space
= out
->len
- out
->used
;
243 len
= strlenW( str
);
246 LPWSTR p
= out
->buf
.W
+ out
->used
;
250 memcpy( p
, str
, len
*sizeof(WCHAR
) );
255 memcpy( p
, str
, space
*sizeof(WCHAR
) );
260 int n
= WideCharToMultiByte( CP_ACP
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
261 LPSTR p
= out
->buf
.A
+ out
->used
;
265 WideCharToMultiByte( CP_ACP
, 0, str
, len
, p
, n
, NULL
, NULL
);
270 WideCharToMultiByte( CP_ACP
, 0, str
, len
, p
, space
, NULL
, NULL
);
276 static inline int pf_output_stringA( pf_output
*out
, LPCSTR str
, int len
)
278 int space
= out
->len
- out
->used
;
284 LPSTR p
= out
->buf
.A
+ out
->used
;
288 memcpy( p
, str
, len
);
293 memcpy( p
, str
, space
);
298 int n
= MultiByteToWideChar( CP_ACP
, 0, str
, len
, NULL
, 0 );
299 LPWSTR p
= out
->buf
.W
+ out
->used
;
303 MultiByteToWideChar( CP_ACP
, 0, str
, len
, p
, n
);
308 MultiByteToWideChar( CP_ACP
, 0, str
, len
, p
, space
);
314 /* pf_fill: takes care of signs, alignment, zero and field padding */
315 static inline int pf_fill( pf_output
*out
, int len
, pf_flags
*flags
, char left
)
319 if( flags
->Sign
&& !( flags
->Format
== 'd' || flags
->Format
== 'i' ) )
322 if( left
&& flags
->Sign
)
324 flags
->FieldLength
--;
326 r
= pf_output_stringA( out
, &flags
->Sign
, 1 );
329 if( ( !left
&& flags
->LeftAlign
) ||
330 ( left
&& !flags
->LeftAlign
))
332 for( i
=0; (i
<(flags
->FieldLength
-len
)) && (r
>=0); i
++ )
334 if( left
&& flags
->PadZero
)
335 r
= pf_output_stringA( out
, "0", 1 );
337 r
= pf_output_stringA( out
, " ", 1 );
341 if( left
&& flags
->Sign
&& !flags
->PadZero
)
342 r
= pf_output_stringA( out
, &flags
->Sign
, 1 );
347 static inline int pf_output_format_W( pf_output
*out
, LPCWSTR str
,
348 int len
, pf_flags
*flags
)
353 len
= strlenW( str
);
355 if (flags
->Precision
>= 0 && flags
->Precision
< len
)
356 len
= flags
->Precision
;
358 r
= pf_fill( out
, len
, flags
, 1 );
361 r
= pf_output_stringW( out
, str
, len
);
364 r
= pf_fill( out
, len
, flags
, 0 );
369 static inline int pf_output_format_A( pf_output
*out
, LPCSTR str
,
370 int len
, pf_flags
*flags
)
377 if (flags
->Precision
>= 0 && flags
->Precision
< len
)
378 len
= flags
->Precision
;
380 r
= pf_fill( out
, len
, flags
, 1 );
383 r
= pf_output_stringA( out
, str
, len
);
386 r
= pf_fill( out
, len
, flags
, 0 );
391 static int pf_handle_string_format( pf_output
*out
, const void* str
, int len
,
392 pf_flags
*flags
, BOOL capital_letter
)
394 if(str
== NULL
) /* catch NULL pointer */
395 return pf_output_format_A( out
, "(null)", -1, flags
);
397 /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */
398 if(flags
->WideString
|| flags
->IntegerLength
== 'l')
399 return pf_output_format_W( out
, str
, len
, flags
);
400 if(flags
->IntegerLength
== 'h')
401 return pf_output_format_A( out
, str
, len
, flags
);
403 /* %s,%c -> chars in ansi functions & wchars in unicode
404 * %S,%C -> wchars in ansi functions & chars in unicode */
405 if( capital_letter
== out
->unicode
) /* either both TRUE or both FALSE */
406 return pf_output_format_A( out
, str
, len
, flags
);
408 return pf_output_format_W( out
, str
, len
, flags
);
411 static inline BOOL
pf_is_integer_format( char fmt
)
413 static const char float_fmts
[] = "diouxX";
416 return strchr( float_fmts
, fmt
) ? TRUE
: FALSE
;
419 static inline BOOL
pf_is_double_format( char fmt
)
421 static const char float_fmts
[] = "aeEfgG";
424 return strchr( float_fmts
, fmt
) ? TRUE
: FALSE
;
427 static inline BOOL
pf_is_valid_format( char fmt
)
429 static const char float_fmts
[] = "acCdeEfgGinouxX";
432 return strchr( float_fmts
, fmt
) ? TRUE
: FALSE
;
435 static void pf_rebuild_format_string( char *p
, pf_flags
*flags
)
440 if( flags
->LeftAlign
)
441 *p
++ = flags
->LeftAlign
;
442 if( flags
->Alternate
)
443 *p
++ = flags
->Alternate
;
445 *p
++ = flags
->PadZero
;
446 if( flags
->FieldLength
)
448 lnx_sprintf(p
, "%d", flags
->FieldLength
);
451 if( flags
->Precision
>= 0 )
453 lnx_sprintf(p
, ".%d", flags
->Precision
);
456 *p
++ = flags
->Format
;
460 /* pf_integer_conv: prints x to buf, including alternate formats and
461 additional precision digits, but not field characters or the sign */
462 static void pf_integer_conv( char *buf
, unsigned int buf_len
, pf_flags
*flags
,
469 char number
[40], *tmp
= number
;
471 if( buf_len
> sizeof number
)
472 tmp
= HeapAlloc( GetProcessHeap(), 0, buf_len
);
475 if( flags
->Format
== 'o' )
477 else if( flags
->Format
== 'x' || flags
->Format
== 'X' )
480 if( flags
->Format
== 'X' )
481 digits
= "0123456789ABCDEFX";
483 digits
= "0123456789abcdefx";
485 if( x
< 0 && ( flags
->Format
== 'd' || flags
->Format
== 'i' ) )
491 /* Do conversion (backwards) */
493 if( x
== 0 && flags
->Precision
)
498 j
= (ULONGLONG
) x
% base
;
499 x
= (ULONGLONG
) x
/ base
;
500 tmp
[i
++] = digits
[j
];
502 k
= flags
->Precision
- i
;
505 if( flags
->Alternate
)
509 tmp
[i
++] = digits
[16];
512 else if( base
== 8 && tmp
[i
-1] != '0' )
516 /* Reverse for buf */
522 /* Adjust precision so pf_fill won't truncate the number later */
523 flags
->Precision
= strlen( buf
);
526 HeapFree( GetProcessHeap(), 0, tmp
);
531 /*********************************************************************
532 * pf_vsnprintf (INTERNAL)
534 * implements both A and W vsnprintf functions
536 static int pf_vsnprintf( pf_output
*out
, const WCHAR
*format
, va_list valist
)
539 LPCWSTR q
, p
= format
;
542 TRACE("format is %s\n",debugstr_w(format
));
545 q
= strchrW( p
, '%' );
547 /* there's no % characters left, output the rest of the string */
550 r
= pf_output_stringW(out
, p
, -1);
557 /* there's characters before the %, output them */
560 r
= pf_output_stringW(out
, p
, q
- p
);
566 /* we must be at a % now, skip over it */
570 /* output a single % character */
573 r
= pf_output_stringW(out
, p
++, 1);
579 /* parse the flags */
580 memset( &flags
, 0, sizeof flags
);
583 if( *p
== '+' || *p
== ' ' )
585 if ( flags
.Sign
!= '+' )
589 flags
.LeftAlign
= *p
;
593 flags
.Alternate
= *p
;
599 /* deal with the field width specifier */
600 flags
.FieldLength
= 0;
603 flags
.FieldLength
= va_arg( valist
, int );
604 if (flags
.FieldLength
< 0)
606 flags
.LeftAlign
= '-';
607 flags
.FieldLength
= -flags
.FieldLength
;
611 else while( isdigit(*p
) )
613 flags
.FieldLength
*= 10;
614 flags
.FieldLength
+= *p
++ - '0';
617 /* deal with precision */
618 flags
.Precision
= -1;
625 flags
.Precision
= va_arg( valist
, int );
628 else while( isdigit(*p
) )
630 flags
.Precision
*= 10;
631 flags
.Precision
+= *p
++ - '0';
635 /* deal with integer width modifier */
638 if( *p
== 'h' || *p
== 'l' || *p
== 'L' )
640 flags
.IntegerLength
= *p
;
645 if( *(p
+1) == '6' && *(p
+2) == '4' )
647 flags
.IntegerDouble
++;
650 else if( *(p
+1) == '3' && *(p
+2) == '2' )
652 else if( isdigit(*(p
+1)) || *(p
+1) == 0 )
658 flags
.WideString
= *p
++;
668 /* output a string */
669 if( flags
.Format
== 's' || flags
.Format
== 'S' )
670 r
= pf_handle_string_format( out
, va_arg(valist
, const void*), -1,
671 &flags
, (flags
.Format
== 'S') );
673 /* output a single character */
674 else if( flags
.Format
== 'c' || flags
.Format
== 'C' )
676 INT ch
= va_arg( valist
, int );
678 r
= pf_handle_string_format( out
, &ch
, 1, &flags
, (flags
.Format
== 'C') );
681 /* output a pointer */
682 else if( flags
.Format
== 'p' )
687 if( flags
.Alternate
)
688 lnx_sprintf(pointer
, "0X%08lX", va_arg(valist
, long));
690 lnx_sprintf(pointer
, "%08lX", va_arg(valist
, long));
691 r
= pf_output_format_A( out
, pointer
, -1, &flags
);
695 else if( flags
.Format
== 'n' )
697 int *x
= va_arg(valist
, int *);
701 /* deal with 64-bit integers */
702 else if( pf_is_integer_format( flags
.Format
) && flags
.IntegerDouble
)
704 char number
[40], *x
= number
;
706 /* Estimate largest possible required buffer size:
707 * Chooses the larger of the field or precision
708 * Includes extra bytes: 1 byte for null, 1 byte for sign,
709 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
710 for a decimal, and 1 byte for an additional float digit. */
711 unsigned x_len
= ((flags
.FieldLength
> flags
.Precision
) ?
712 flags
.FieldLength
: flags
.Precision
) + 10;
714 if( x_len
>= sizeof number
)
715 x
= HeapAlloc( GetProcessHeap(), 0, x_len
);
717 pf_integer_conv( x
, x_len
, &flags
, va_arg(valist
, LONGLONG
) );
719 r
= pf_output_format_A( out
, x
, -1, &flags
);
721 HeapFree( GetProcessHeap(), 0, x
);
724 /* deal with integers and floats using libc's printf */
725 else if( pf_is_valid_format( flags
.Format
) )
727 char fmt
[20], number
[40], *x
= number
;
729 /* Estimate largest possible required buffer size:
730 * Chooses the larger of the field or precision
731 * Includes extra bytes: 1 byte for null, 1 byte for sign,
732 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
733 for a decimal, and 1 byte for an additional float digit. */
734 unsigned x_len
= ((flags
.FieldLength
> flags
.Precision
) ?
735 flags
.FieldLength
: flags
.Precision
) + 10;
737 if( x_len
>= sizeof number
)
738 x
= HeapAlloc( GetProcessHeap(), 0, x_len
);
740 pf_rebuild_format_string( fmt
, &flags
);
742 if( pf_is_double_format( flags
.Format
) )
743 lnx_sprintf( x
, fmt
, va_arg(valist
, double) );
745 lnx_sprintf( x
, fmt
, va_arg(valist
, int) );
747 r
= pf_output_stringA( out
, x
, -1 );
749 HeapFree( GetProcessHeap(), 0, x
);
759 /* check we reached the end, and null terminate the string */
761 pf_output_stringW( out
, p
, 1 );
763 return out
->used
- 1;
766 /*********************************************************************
767 * _vsnprintf (MSVCRT.@)
769 int CDECL
_vsnprintf( char *str
, size_t len
,
770 const char *format
, va_list valist
)
773 LPWSTR formatW
= NULL
;
784 sz
= MultiByteToWideChar( CP_ACP
, 0, format
, -1, NULL
, 0 );
785 formatW
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
786 MultiByteToWideChar( CP_ACP
, 0, format
, -1, formatW
, sz
);
789 r
= pf_vsnprintf( &out
, formatW
, valist
);
791 HeapFree( GetProcessHeap(), 0, formatW
);
796 /*********************************************************************
797 * vsprintf (MSVCRT.@)
799 int CDECL
vsprintf( char *str
, const char *format
, va_list valist
)
801 return _vsnprintf(str
, INT_MAX
, format
, valist
);
804 /*********************************************************************
805 * _snprintf (MSVCRT.@)
807 int CDECL
_snprintf(char *str
, size_t len
, const char *format
, ...)
811 va_start(valist
, format
);
812 retval
= _vsnprintf(str
, len
, format
, valist
);
817 /*********************************************************************
818 * _vsnwsprintf (MSVCRT.@)
820 int CDECL
_vsnwprintf( wchar_t *str
, size_t len
,
821 const wchar_t *format
, va_list valist
)
830 return pf_vsnprintf( &out
, format
, valist
);
833 /*********************************************************************
834 * _snwprintf (MSVCRT.@)
836 int CDECL
_snwprintf( wchar_t *str
, size_t len
, const wchar_t *format
, ...)
840 va_start(valist
, format
);
841 retval
= _vsnwprintf(str
, len
, format
, valist
);
846 /*********************************************************************
849 int CDECL
sprintf( char *str
, const char *format
, ... )
854 va_start( ap
, format
);
855 r
= _vsnprintf( str
, INT_MAX
, format
, ap
);
860 /*********************************************************************
861 * swprintf (MSVCRT.@)
863 int CDECL
swprintf( wchar_t *str
, const wchar_t *format
, ... )
868 va_start( ap
, format
);
869 r
= _vsnwprintf( str
, INT_MAX
, format
, ap
);
874 /*********************************************************************
875 * vswprintf (MSVCRT.@)
877 int CDECL
vswprintf( wchar_t* str
, const wchar_t* format
, va_list args
)
879 return _vsnwprintf( str
, INT_MAX
, format
, args
);
883 /*********************************************************************
886 int CDECL
wcscoll( const wchar_t* str1
, const wchar_t* str2
)
888 /* FIXME: handle collates */
889 return strcmpW( str1
, str2
);
892 /*********************************************************************
895 wchar_t* CDECL
wcspbrk( const wchar_t* str
, const wchar_t* accept
)
900 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (wchar_t*)str
;
907 /*********************************************************************
910 wchar_t * CDECL
wcstok( wchar_t *str
, const wchar_t *delim
)
912 MSVCRT_thread_data
*data
= msvcrt_get_thread_data();
916 if (!(str
= data
->wcstok_next
)) return NULL
;
918 while (*str
&& strchrW( delim
, *str
)) str
++;
919 if (!*str
) return NULL
;
921 while (*str
&& !strchrW( delim
, *str
)) str
++;
922 if (*str
) *str
++ = 0;
923 data
->wcstok_next
= str
;
927 /*********************************************************************
930 INT CDECL
wctomb(char *mbchar
, wchar_t wchar
)
932 BOOL bUsedDefaultChar
;
933 char chMultiByte
[MB_LEN_MAX
];
936 /* At least one parameter needs to be given, the length of a null character cannot be queried (verified by tests under WinXP SP2) */
937 if(!mbchar
&& !wchar
)
940 /* Use WideCharToMultiByte for doing the conversion using the codepage currently set with setlocale() */
941 nBytes
= WideCharToMultiByte(MSVCRT___lc_codepage
, 0, &wchar
, 1, chMultiByte
, MB_LEN_MAX
, NULL
, &bUsedDefaultChar
);
943 /* Only copy the character if an 'mbchar' pointer was given.
945 The "C" locale is emulated with codepage 1252 here. This codepage has a default character "?", but the "C" locale doesn't have one.
946 Therefore don't copy the character in this case. */
947 if(mbchar
&& !(MSVCRT_current_lc_all
[0] == 'C' && !MSVCRT_current_lc_all
[1] && bUsedDefaultChar
))
948 memcpy(mbchar
, chMultiByte
, nBytes
);
950 /* If the default character was used, set errno to EILSEQ and return -1. */
957 /* Otherwise return the number of bytes this character occupies. */
961 size_t CDECL
wcstombs(char *mbstr
, const wchar_t *wcstr
, size_t count
)
963 BOOL bUsedDefaultChar
;
967 /* Does the caller query for output buffer size? */
972 /* If we currently use the "C" locale, the length of the input string is returned (verified by tests under WinXP SP2) */
973 if(MSVCRT_current_lc_all
[0] == 'C' && !MSVCRT_current_lc_all
[1])
974 return wcslen(wcstr
);
976 /* Otherwise check the length each character needs and build a final return value out of this */
977 count
= wcslen(wcstr
);
980 while((int)(--count
) >= 0 && *wcstr
)
982 /* Get the length of this character */
983 nResult
= wctomb(NULL
, *wcstr
++);
985 /* If this character is not convertible in the current locale, the end result will be -1 */
992 /* Return the final length */
996 /* Convert the string then */
997 bUsedDefaultChar
= FALSE
;
1001 char chMultiByte
[MB_LEN_MAX
];
1004 /* Are we at the terminating null character? */
1007 /* Set the null character, but don't increment the pointer as the returned length never includes the terminating null character */
1012 /* Convert this character into the temporary chMultiByte variable */
1013 ZeroMemory(chMultiByte
, MB_LEN_MAX
);
1014 nResult
= wctomb(chMultiByte
, *wcstr
++);
1016 /* Check if this was an invalid character */
1018 bUsedDefaultChar
= TRUE
;
1020 /* If we got no character, stop the conversion process here */
1024 /* Determine whether this is a double-byte or a single-byte character */
1030 /* Decrease 'count' by the character length and check if the buffer can still hold the full character */
1036 /* It can, so copy it and move the pointer forward */
1037 memcpy(p
, chMultiByte
, uLength
);
1041 if(bUsedDefaultChar
)
1044 /* Return the length in bytes of the copied characters (without the terminating null character) */
1050 /*********************************************************************
1051 * iswalnum (MSVCRT.@)
1053 INT CDECL
iswalnum( wchar_t wc
)
1055 return isalnumW( wc
);
1058 /*********************************************************************
1059 * iswalpha (MSVCRT.@)
1061 INT CDECL
iswalpha( wchar_t wc
)
1063 return isalphaW( wc
);
1066 /*********************************************************************
1067 * iswcntrl (MSVCRT.@)
1069 INT CDECL
iswcntrl( wchar_t wc
)
1071 return iscntrlW( wc
);
1074 /*********************************************************************
1075 * iswdigit (MSVCRT.@)
1077 INT CDECL
iswdigit( wchar_t wc
)
1079 return isdigitW( wc
);
1082 /*********************************************************************
1083 * iswgraph (MSVCRT.@)
1085 INT CDECL
iswgraph( wchar_t wc
)
1087 return isgraphW( wc
);
1090 /*********************************************************************
1091 * iswlower (MSVCRT.@)
1093 INT CDECL
iswlower( wchar_t wc
)
1095 return islowerW( wc
);
1098 /*********************************************************************
1099 * iswprint (MSVCRT.@)
1101 INT CDECL
iswprint( wchar_t wc
)
1103 return isprintW( wc
);
1106 /*********************************************************************
1107 * iswpunct (MSVCRT.@)
1109 INT CDECL
iswpunct( wchar_t wc
)
1111 return ispunctW( wc
);
1114 /*********************************************************************
1115 * iswspace (MSVCRT.@)
1117 INT CDECL
iswspace( wchar_t wc
)
1119 return isspaceW( wc
);
1122 /*********************************************************************
1123 * iswupper (MSVCRT.@)
1125 INT CDECL
iswupper( wchar_t wc
)
1127 return isupperW( wc
);
1130 /*********************************************************************
1131 * iswxdigit (MSVCRT.@)
1133 INT CDECL
iswxdigit( wchar_t wc
)
1135 return isxdigitW( wc
);
1140 /*********************************************************************
1141 * wcscpy_s (MSVCRT.@)
1143 INT CDECL
wcscpy_s( wchar_t* wcDest
, size_t numElement
, const wchar_t *wcSrc
)
1147 if(!wcDest
|| !numElement
)
1157 size
= strlenW(wcSrc
) + 1;
1159 if(size
> numElement
)
1164 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1169 /******************************************************************
1170 * wcsncpy_s (MSVCRT.@)
1172 INT CDECL
wcsncpy_s( wchar_t* wcDest
, size_t numElement
, const wchar_t *wcSrc
,
1177 if (!wcDest
|| !numElement
)
1187 size
= min(strlenW(wcSrc
), count
);
1189 if (size
>= numElement
)
1194 memcpy( wcDest
, wcSrc
, size
*sizeof(WCHAR
) );
1195 wcDest
[size
] = '\0';