dnsapi: Sign-compare warnings fix.
[wine/gsoc_dplay.git] / dlls / msvcrt / wcs.c
blob8eccb39552bd65cfb6ea9c5576436b474416e074
1 /*
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
21 #include <limits.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <assert.h>
25 #include "msvcrt.h"
26 #include "winnls.h"
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
33 /*********************************************************************
34 * _wcsdup (MSVCRT.@)
36 MSVCRT_wchar_t* CDECL _wcsdup( const MSVCRT_wchar_t* str )
38 MSVCRT_wchar_t* ret = NULL;
39 if (str)
41 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
42 ret = MSVCRT_malloc( size );
43 if (ret) memcpy( ret, str, size );
45 return ret;
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 /*********************************************************************
58 * _wcsnset (MSVCRT.@)
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;
64 return ret;
67 /*********************************************************************
68 * _wcsrev (MSVCRT.@)
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;
74 while (end > str)
76 MSVCRT_wchar_t t = *end;
77 *end-- = *str;
78 *str++ = t;
80 return ret;
83 /*********************************************************************
84 * _wcsset (MSVCRT.@)
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;
90 return ret;
93 /*********************************************************************
94 * wcstod (MSVCRT.@)
96 double CDECL MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
98 const MSVCRT_wchar_t* str = lpszStr;
99 int negative = 0;
100 double ret = 0, divisor = 10.0;
102 TRACE("(%s,%p) semi-stub\n", debugstr_w(lpszStr), end);
104 /* FIXME:
105 * - Should set errno on failure
106 * - Should fail on overflow
107 * - Need to check which input formats are allowed
109 while (isspaceW(*str))
110 str++;
112 if (*str == '-')
114 negative = 1;
115 str++;
118 while (isdigitW(*str))
120 ret = ret * 10.0 + (*str - '0');
121 str++;
123 if (*str == '.')
124 str++;
125 while (isdigitW(*str))
127 ret = ret + (*str - '0') / divisor;
128 divisor *= 10;
129 str++;
132 if (*str == 'E' || *str == 'e' || *str == 'D' || *str == 'd')
134 int negativeExponent = 0;
135 int exponent = 0;
136 if (*(++str) == '-')
138 negativeExponent = 1;
139 str++;
141 while (isdigitW(*str))
143 exponent = exponent * 10 + (*str - '0');
144 str++;
146 if (exponent != 0)
148 if (negativeExponent)
149 ret = ret / pow(10.0, exponent);
150 else
151 ret = ret * pow(10.0, exponent);
155 if (negative)
156 ret = -ret;
158 if (end)
159 *end = (MSVCRT_wchar_t*)str;
161 TRACE("returning %g\n", ret);
162 return ret;
166 typedef struct pf_output_t
168 int used;
169 int len;
170 BOOL unicode;
171 union {
172 LPWSTR W;
173 LPSTR A;
174 } buf;
175 } pf_output;
177 typedef struct pf_flags_t
179 char Sign, LeftAlign, Alternate, PadZero;
180 int FieldLength, Precision;
181 char IntegerLength, IntegerDouble;
182 char WideString;
183 char Format;
184 } pf_flags;
187 * writes a string of characters to the output
188 * returns -1 if the string doesn't fit in the output buffer
189 * return the length of the string if all characters were written
191 static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
193 int space = out->len - out->used;
195 if( len < 0 )
196 len = strlenW( str );
197 if( out->unicode )
199 LPWSTR p = out->buf.W + out->used;
201 if( space >= len )
203 memcpy( p, str, len*sizeof(WCHAR) );
204 out->used += len;
205 return len;
207 if( space > 0 )
208 memcpy( p, str, space*sizeof(WCHAR) );
209 out->used += len;
211 else
213 int n = WideCharToMultiByte( CP_ACP, 0, str, len, NULL, 0, NULL, NULL );
214 LPSTR p = out->buf.A + out->used;
216 if( space >= n )
218 WideCharToMultiByte( CP_ACP, 0, str, len, p, n, NULL, NULL );
219 out->used += n;
220 return len;
222 if( space > 0 )
223 WideCharToMultiByte( CP_ACP, 0, str, len, p, space, NULL, NULL );
224 out->used += n;
226 return -1;
229 static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
231 int space = out->len - out->used;
233 if( len < 0 )
234 len = strlen( str );
235 if( !out->unicode )
237 LPSTR p = out->buf.A + out->used;
239 if( space >= len )
241 memcpy( p, str, len );
242 out->used += len;
243 return len;
245 if( space > 0 )
246 memcpy( p, str, space );
247 out->used += len;
249 else
251 int n = MultiByteToWideChar( CP_ACP, 0, str, len, NULL, 0 );
252 LPWSTR p = out->buf.W + out->used;
254 if( space >= n )
256 MultiByteToWideChar( CP_ACP, 0, str, len, p, n );
257 out->used += n;
258 return len;
260 if( space > 0 )
261 MultiByteToWideChar( CP_ACP, 0, str, len, p, space );
262 out->used += n;
264 return -1;
267 /* pf_fill: takes care of signs, alignment, zero and field padding */
268 static inline int pf_fill( pf_output *out, int len, pf_flags *flags, char left )
270 int i, r = 0;
272 if( flags->Sign && !( flags->Format == 'd' || flags->Format == 'i' ) )
273 flags->Sign = 0;
275 if( left && flags->Sign )
277 flags->FieldLength--;
278 if( flags->PadZero )
279 r = pf_output_stringA( out, &flags->Sign, 1 );
282 if( ( !left && flags->LeftAlign ) ||
283 ( left && !flags->LeftAlign ))
285 for( i=0; (i<(flags->FieldLength-len)) && (r>=0); i++ )
287 if( left && flags->PadZero )
288 r = pf_output_stringA( out, "0", 1 );
289 else
290 r = pf_output_stringA( out, " ", 1 );
294 if( left && flags->Sign && !flags->PadZero )
295 r = pf_output_stringA( out, &flags->Sign, 1 );
297 return r;
300 static inline int pf_output_format_W( pf_output *out, LPCWSTR str,
301 int len, pf_flags *flags )
303 int r = 0;
305 if( len < 0 )
306 len = strlenW( str );
308 if (flags->Precision >= 0 && flags->Precision < len)
309 len = flags->Precision;
311 r = pf_fill( out, len, flags, 1 );
313 if( r>=0 )
314 r = pf_output_stringW( out, str, len );
316 if( r>=0 )
317 r = pf_fill( out, len, flags, 0 );
319 return r;
322 static inline int pf_output_format_A( pf_output *out, LPCSTR str,
323 int len, pf_flags *flags )
325 int r = 0;
327 if( len < 0 )
328 len = strlen( str );
330 if (flags->Precision >= 0 && flags->Precision < len)
331 len = flags->Precision;
333 r = pf_fill( out, len, flags, 1 );
335 if( r>=0 )
336 r = pf_output_stringA( out, str, len );
338 if( r>=0 )
339 r = pf_fill( out, len, flags, 0 );
341 return r;
344 static int pf_handle_string_format( pf_output *out, const void* str, int len,
345 pf_flags *flags, BOOL capital_letter)
347 if(str == NULL) /* catch NULL pointer */
348 return pf_output_format_A( out, "(null)", -1, flags);
350 /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */
351 if(flags->WideString || flags->IntegerLength == 'l')
352 return pf_output_format_W( out, str, len, flags);
353 if(flags->IntegerLength == 'h')
354 return pf_output_format_A( out, str, len, flags);
356 /* %s,%c -> chars in ansi functions & wchars in unicode
357 * %S,%C -> wchars in ansi functions & chars in unicode */
358 if( capital_letter == out->unicode) /* either both TRUE or both FALSE */
359 return pf_output_format_A( out, str, len, flags);
360 else
361 return pf_output_format_W( out, str, len, flags);
364 static inline BOOL pf_is_integer_format( char fmt )
366 static const char float_fmts[] = "diouxX";
367 if (!fmt)
368 return FALSE;
369 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
372 static inline BOOL pf_is_double_format( char fmt )
374 static const char float_fmts[] = "aeEfgG";
375 if (!fmt)
376 return FALSE;
377 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
380 static inline BOOL pf_is_valid_format( char fmt )
382 static const char float_fmts[] = "acCdeEfgGinouxX";
383 if (!fmt)
384 return FALSE;
385 return strchr( float_fmts, fmt ) ? TRUE : FALSE;
388 static void pf_rebuild_format_string( char *p, pf_flags *flags )
390 *p++ = '%';
391 if( flags->Sign )
392 *p++ = flags->Sign;
393 if( flags->LeftAlign )
394 *p++ = flags->LeftAlign;
395 if( flags->Alternate )
396 *p++ = flags->Alternate;
397 if( flags->PadZero )
398 *p++ = flags->PadZero;
399 if( flags->FieldLength )
401 sprintf(p, "%d", flags->FieldLength);
402 p += strlen(p);
404 if( flags->Precision >= 0 )
406 sprintf(p, ".%d", flags->Precision);
407 p += strlen(p);
409 *p++ = flags->Format;
410 *p++ = 0;
413 /* pf_integer_conv: prints x to buf, including alternate formats and
414 additional precision digits, but not field characters or the sign */
415 static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags,
416 LONGLONG x )
418 unsigned int base;
419 const char *digits;
421 int i, j, k;
422 char number[40], *tmp = number;
424 if( buf_len > sizeof number )
425 tmp = HeapAlloc( GetProcessHeap(), 0, buf_len );
427 base = 10;
428 if( flags->Format == 'o' )
429 base = 8;
430 else if( flags->Format == 'x' || flags->Format == 'X' )
431 base = 16;
433 if( flags->Format == 'X' )
434 digits = "0123456789ABCDEFX";
435 else
436 digits = "0123456789abcdefx";
438 if( x < 0 && ( flags->Format == 'd' || flags->Format == 'i' ) )
440 x = -x;
441 flags->Sign = '-';
444 /* Do conversion (backwards) */
445 i = 0;
446 if( x == 0 && flags->Precision )
447 tmp[i++] = '0';
448 else
449 while( x != 0 )
451 j = (ULONGLONG) x % base;
452 x = (ULONGLONG) x / base;
453 tmp[i++] = digits[j];
455 k = flags->Precision - i;
456 while( k-- > 0 )
457 tmp[i++] = '0';
458 if( flags->Alternate )
460 if( base == 16 )
462 tmp[i++] = digits[16];
463 tmp[i++] = '0';
465 else if( base == 8 && tmp[i-1] != '0' )
466 tmp[i++] = '0';
469 /* Reverse for buf */
470 j = 0;
471 while( i-- > 0 )
472 buf[j++] = tmp[i];
473 buf[j] = '\0';
475 /* Adjust precision so pf_fill won't truncate the number later */
476 flags->Precision = strlen( buf );
478 if( tmp != number )
479 HeapFree( GetProcessHeap(), 0, tmp );
481 return;
484 /* pf_fixup_exponent: convert a string containing a 2 digit exponent
485 to 3 digits, accounting for padding, in place. Needed to match
486 the native printf's which always use 3 digits. */
487 static void pf_fixup_exponent( char *buf )
489 char* tmp = buf;
491 while (tmp[0] && toupper(tmp[0]) != 'E')
492 tmp++;
494 if (tmp[0] && (tmp[1] == '+' || tmp[1] == '-') &&
495 isdigit(tmp[2]) && isdigit(tmp[3]))
497 char final;
499 if (isdigit(tmp[4]))
500 return; /* Exponent already 3 digits */
502 /* We have a 2 digit exponent. Prepend '0' to make it 3 */
503 tmp += 2;
504 final = tmp[2];
505 tmp[2] = tmp[1];
506 tmp[1] = tmp[0];
507 tmp[0] = '0';
508 if (final == '\0')
510 /* We didn't expand into trailing space, so this string isn't left
511 * justified. Terminate the string and strip a ' ' at the start of
512 * the string if there is one (as there may be if the string is
513 * right justified).
515 tmp[3] = '\0';
516 if (buf[0] == ' ')
517 memmove(buf, buf + 1, (tmp - buf) + 3);
519 /* Otherwise, we expanded into trailing space -> nothing to do */
523 /*********************************************************************
524 * pf_vsnprintf (INTERNAL)
526 * implements both A and W vsnprintf functions
528 static int pf_vsnprintf( pf_output *out, const WCHAR *format, va_list valist )
530 int r;
531 LPCWSTR q, p = format;
532 pf_flags flags;
534 TRACE("format is %s\n",debugstr_w(format));
535 while (*p)
537 q = strchrW( p, '%' );
539 /* there's no % characters left, output the rest of the string */
540 if( !q )
542 r = pf_output_stringW(out, p, -1);
543 if( r<0 )
544 return r;
545 p += r;
546 continue;
549 /* there's characters before the %, output them */
550 if( q != p )
552 r = pf_output_stringW(out, p, q - p);
553 if( r<0 )
554 return r;
555 p = q;
558 /* we must be at a % now, skip over it */
559 assert( *p == '%' );
560 p++;
562 /* output a single % character */
563 if( *p == '%' )
565 r = pf_output_stringW(out, p++, 1);
566 if( r<0 )
567 return r;
568 continue;
571 /* parse the flags */
572 memset( &flags, 0, sizeof flags );
573 while (*p)
575 if( *p == '+' || *p == ' ' )
577 if ( flags.Sign != '+' )
578 flags.Sign = *p;
580 else if( *p == '-' )
581 flags.LeftAlign = *p;
582 else if( *p == '0' )
583 flags.PadZero = *p;
584 else if( *p == '#' )
585 flags.Alternate = *p;
586 else
587 break;
588 p++;
591 /* deal with the field width specifier */
592 flags.FieldLength = 0;
593 if( *p == '*' )
595 flags.FieldLength = va_arg( valist, int );
596 if (flags.FieldLength < 0)
598 flags.LeftAlign = '-';
599 flags.FieldLength = -flags.FieldLength;
601 p++;
603 else while( isdigit(*p) )
605 flags.FieldLength *= 10;
606 flags.FieldLength += *p++ - '0';
609 /* deal with precision */
610 flags.Precision = -1;
611 if( *p == '.' )
613 flags.Precision = 0;
614 p++;
615 if( *p == '*' )
617 flags.Precision = va_arg( valist, int );
618 p++;
620 else while( isdigit(*p) )
622 flags.Precision *= 10;
623 flags.Precision += *p++ - '0';
627 /* deal with integer width modifier */
628 while( *p )
630 if( *p == 'h' || *p == 'l' || *p == 'L' )
632 flags.IntegerLength = *p;
633 p++;
635 else if( *p == 'I' )
637 if( *(p+1) == '6' && *(p+2) == '4' )
639 flags.IntegerDouble++;
640 p += 3;
642 else if( *(p+1) == '3' && *(p+2) == '2' )
643 p += 3;
644 else if( isdigit(*(p+1)) || *(p+1) == 0 )
645 break;
646 else
647 p++;
649 else if( *p == 'w' )
650 flags.WideString = *p++;
651 else if( *p == 'F' )
652 p++; /* ignore */
653 else
654 break;
657 flags.Format = *p;
658 r = 0;
660 /* output a string */
661 if( flags.Format == 's' || flags.Format == 'S' )
662 r = pf_handle_string_format( out, va_arg(valist, const void*), -1,
663 &flags, (flags.Format == 'S') );
665 /* output a single character */
666 else if( flags.Format == 'c' || flags.Format == 'C' )
668 INT ch = va_arg( valist, int );
670 r = pf_handle_string_format( out, &ch, 1, &flags, (flags.Format == 'C') );
673 /* output a pointer */
674 else if( flags.Format == 'p' )
676 char pointer[11];
678 flags.PadZero = 0;
679 if( flags.Alternate )
680 sprintf(pointer, "0X%08lX", va_arg(valist, long));
681 else
682 sprintf(pointer, "%08lX", va_arg(valist, long));
683 r = pf_output_format_A( out, pointer, -1, &flags );
686 /* deal with %n */
687 else if( flags.Format == 'n' )
689 int *x = va_arg(valist, int *);
690 *x = out->used;
693 /* deal with 64-bit integers */
694 else if( pf_is_integer_format( flags.Format ) && flags.IntegerDouble )
696 char number[40], *x = number;
698 /* Estimate largest possible required buffer size:
699 * Chooses the larger of the field or precision
700 * Includes extra bytes: 1 byte for null, 1 byte for sign,
701 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
702 for a decimal, and 1 byte for an additional float digit. */
703 int x_len = ((flags.FieldLength > flags.Precision) ?
704 flags.FieldLength : flags.Precision) + 10;
706 if( x_len >= sizeof number)
707 x = HeapAlloc( GetProcessHeap(), 0, x_len );
709 pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) );
711 r = pf_output_format_A( out, x, -1, &flags );
712 if( x != number )
713 HeapFree( GetProcessHeap(), 0, x );
716 /* deal with integers and floats using libc's printf */
717 else if( pf_is_valid_format( flags.Format ) )
719 char fmt[20], number[40], *x = number;
721 /* Estimate largest possible required buffer size:
722 * Chooses the larger of the field or precision
723 * Includes extra bytes: 1 byte for null, 1 byte for sign,
724 4 bytes for exponent, 2 bytes for alternate formats, 1 byte
725 for a decimal, and 1 byte for an additional float digit. */
726 int x_len = ((flags.FieldLength > flags.Precision) ?
727 flags.FieldLength : flags.Precision) + 10;
729 if( x_len >= sizeof number)
730 x = HeapAlloc( GetProcessHeap(), 0, x_len );
732 pf_rebuild_format_string( fmt, &flags );
734 if( pf_is_double_format( flags.Format ) )
736 sprintf( x, fmt, va_arg(valist, double) );
737 if (toupper(flags.Format) == 'E' || toupper(flags.Format) == 'G')
738 pf_fixup_exponent( x );
740 else
741 sprintf( x, fmt, va_arg(valist, int) );
743 r = pf_output_stringA( out, x, -1 );
744 if( x != number )
745 HeapFree( GetProcessHeap(), 0, x );
747 else
748 continue;
750 if( r<0 )
751 return r;
752 p++;
755 /* check we reached the end, and null terminate the string */
756 assert( *p == 0 );
757 pf_output_stringW( out, p, 1 );
759 return out->used - 1;
762 /*********************************************************************
763 * _vsnprintf (MSVCRT.@)
765 int CDECL MSVCRT_vsnprintf( char *str, unsigned int len,
766 const char *format, va_list valist )
768 DWORD sz;
769 LPWSTR formatW = NULL;
770 pf_output out;
771 int r;
773 out.unicode = FALSE;
774 out.buf.A = str;
775 out.used = 0;
776 out.len = len;
778 if( format )
780 sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 );
781 formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
782 MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz );
785 r = pf_vsnprintf( &out, formatW, valist );
787 HeapFree( GetProcessHeap(), 0, formatW );
789 return r;
792 /*********************************************************************
793 * vsprintf (MSVCRT.@)
795 int CDECL MSVCRT_vsprintf( char *str, const char *format, va_list valist)
797 return MSVCRT_vsnprintf(str, INT_MAX, format, valist);
800 /*********************************************************************
801 * _snprintf (MSVCRT.@)
803 int CDECL MSVCRT__snprintf(char *str, unsigned int len, const char *format, ...)
805 int retval;
806 va_list valist;
807 va_start(valist, format);
808 retval = MSVCRT_vsnprintf(str, len, format, valist);
809 va_end(valist);
810 return retval;
813 /*********************************************************************
814 * _vsnwsprintf (MSVCRT.@)
816 int CDECL MSVCRT_vsnwprintf( MSVCRT_wchar_t *str, unsigned int len,
817 const MSVCRT_wchar_t *format, va_list valist )
819 pf_output out;
821 out.unicode = TRUE;
822 out.buf.W = str;
823 out.used = 0;
824 out.len = len;
826 return pf_vsnprintf( &out, format, valist );
829 /*********************************************************************
830 * _snwprintf (MSVCRT.@)
832 int CDECL MSVCRT__snwprintf( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format, ...)
834 int retval;
835 va_list valist;
836 va_start(valist, format);
837 retval = MSVCRT_vsnwprintf(str, len, format, valist);
838 va_end(valist);
839 return retval;
842 /*********************************************************************
843 * sprintf (MSVCRT.@)
845 int CDECL MSVCRT_sprintf( char *str, const char *format, ... )
847 va_list ap;
848 int r;
850 va_start( ap, format );
851 r = MSVCRT_vsnprintf( str, INT_MAX, format, ap );
852 va_end( ap );
853 return r;
856 /*********************************************************************
857 * swprintf (MSVCRT.@)
859 int CDECL MSVCRT_swprintf( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ... )
861 va_list ap;
862 int r;
864 va_start( ap, format );
865 r = MSVCRT_vsnwprintf( str, INT_MAX, format, ap );
866 va_end( ap );
867 return r;
870 /*********************************************************************
871 * vswprintf (MSVCRT.@)
873 int CDECL MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, va_list args )
875 return MSVCRT_vsnwprintf( str, INT_MAX, format, args );
878 /*********************************************************************
879 * wcscoll (MSVCRT.@)
881 int CDECL MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
883 /* FIXME: handle collates */
884 return strcmpW( str1, str2 );
887 /*********************************************************************
888 * wcspbrk (MSVCRT.@)
890 MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
892 const MSVCRT_wchar_t* p;
893 while (*str)
895 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
896 str++;
898 return NULL;
901 /*********************************************************************
902 * wcstok (MSVCRT.@)
904 MSVCRT_wchar_t * CDECL MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
906 thread_data_t *data = msvcrt_get_thread_data();
907 MSVCRT_wchar_t *ret;
909 if (!str)
910 if (!(str = data->wcstok_next)) return NULL;
912 while (*str && strchrW( delim, *str )) str++;
913 if (!*str) return NULL;
914 ret = str++;
915 while (*str && !strchrW( delim, *str )) str++;
916 if (*str) *str++ = 0;
917 data->wcstok_next = str;
918 return ret;
922 /*********************************************************************
923 * wctomb (MSVCRT.@)
925 INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
927 return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
930 /*********************************************************************
931 * iswalnum (MSVCRT.@)
933 INT CDECL MSVCRT_iswalnum( MSVCRT_wchar_t wc )
935 return isalnumW( wc );
938 /*********************************************************************
939 * iswalpha (MSVCRT.@)
941 INT CDECL MSVCRT_iswalpha( MSVCRT_wchar_t wc )
943 return isalphaW( wc );
946 /*********************************************************************
947 * iswcntrl (MSVCRT.@)
949 INT CDECL MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
951 return iscntrlW( wc );
954 /*********************************************************************
955 * iswdigit (MSVCRT.@)
957 INT CDECL MSVCRT_iswdigit( MSVCRT_wchar_t wc )
959 return isdigitW( wc );
962 /*********************************************************************
963 * iswgraph (MSVCRT.@)
965 INT CDECL MSVCRT_iswgraph( MSVCRT_wchar_t wc )
967 return isgraphW( wc );
970 /*********************************************************************
971 * iswlower (MSVCRT.@)
973 INT CDECL MSVCRT_iswlower( MSVCRT_wchar_t wc )
975 return islowerW( wc );
978 /*********************************************************************
979 * iswprint (MSVCRT.@)
981 INT CDECL MSVCRT_iswprint( MSVCRT_wchar_t wc )
983 return isprintW( wc );
986 /*********************************************************************
987 * iswpunct (MSVCRT.@)
989 INT CDECL MSVCRT_iswpunct( MSVCRT_wchar_t wc )
991 return ispunctW( wc );
994 /*********************************************************************
995 * iswspace (MSVCRT.@)
997 INT CDECL MSVCRT_iswspace( MSVCRT_wchar_t wc )
999 return isspaceW( wc );
1002 /*********************************************************************
1003 * iswupper (MSVCRT.@)
1005 INT CDECL MSVCRT_iswupper( MSVCRT_wchar_t wc )
1007 return isupperW( wc );
1010 /*********************************************************************
1011 * iswxdigit (MSVCRT.@)
1013 INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
1015 return isxdigitW( wc );
1018 /*********************************************************************
1019 * wcscpy_s (MSVCRT.@)
1021 INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc)
1023 INT size = 0;
1025 if(!wcDest || !numElement)
1026 return MSVCRT_EINVAL;
1028 wcDest[0] = 0;
1030 if(!wcSrc)
1032 return MSVCRT_EINVAL;
1035 size = strlenW(wcSrc) + 1;
1037 if(size > numElement)
1039 return MSVCRT_ERANGE;
1042 if(size > numElement)
1043 size = numElement;
1045 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
1047 return 0;