d3dx9: Introduce separate functions for restoring and capturing device state.
[wine.git] / dlls / msvcrt / wcs.c
blobd9fb0a5ff08796bd4b59f948a0e5f31b59d08b7c
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 "config.h"
22 #include "wine/port.h"
24 #include <limits.h>
25 #include <stdio.h>
26 #include <math.h>
27 #include <assert.h>
28 #include "msvcrt.h"
29 #include "winnls.h"
30 #include "wtypes.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 static BOOL n_format_enabled = TRUE;
38 #include "printf.h"
39 #define PRINTF_WIDE
40 #include "printf.h"
41 #undef PRINTF_WIDE
43 /* _get_printf_count_output - not exported in native msvcrt */
44 int CDECL MSVCRT__get_printf_count_output( void )
46 return n_format_enabled ? 1 : 0;
49 /* _set_printf_count_output - not exported in native msvcrt */
50 int CDECL MSVCRT__set_printf_count_output( int enable )
52 BOOL old = n_format_enabled;
53 n_format_enabled = (enable ? TRUE : FALSE);
54 return old ? 1 : 0;
57 /*********************************************************************
58 * _wcsdup (MSVCRT.@)
60 MSVCRT_wchar_t* CDECL MSVCRT__wcsdup( const MSVCRT_wchar_t* str )
62 MSVCRT_wchar_t* ret = NULL;
63 if (str)
65 int size = (strlenW(str) + 1) * sizeof(MSVCRT_wchar_t);
66 ret = MSVCRT_malloc( size );
67 if (ret) memcpy( ret, str, size );
69 return ret;
72 /*********************************************************************
73 * _wcsicoll (MSVCRT.@)
75 INT CDECL MSVCRT__wcsicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
77 /* FIXME: handle collates */
78 return strcmpiW( str1, str2 );
81 /*********************************************************************
82 * _wcsnicoll (MSVCRT.@)
84 INT CDECL MSVCRT__wcsnicoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2, MSVCRT_size_t count )
86 /* FIXME: handle collates */
87 return strncmpiW( str1, str2, count );
90 /*********************************************************************
91 * _wcsnset (MSVCRT.@)
93 MSVCRT_wchar_t* CDECL MSVCRT__wcsnset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c, MSVCRT_size_t n )
95 MSVCRT_wchar_t* ret = str;
96 while ((n-- > 0) && *str) *str++ = c;
97 return ret;
100 /*********************************************************************
101 * _wcsrev (MSVCRT.@)
103 MSVCRT_wchar_t* CDECL MSVCRT__wcsrev( MSVCRT_wchar_t* str )
105 MSVCRT_wchar_t* ret = str;
106 MSVCRT_wchar_t* end = str + strlenW(str) - 1;
107 while (end > str)
109 MSVCRT_wchar_t t = *end;
110 *end-- = *str;
111 *str++ = t;
113 return ret;
116 /*********************************************************************
117 * _wcsset (MSVCRT.@)
119 MSVCRT_wchar_t* CDECL MSVCRT__wcsset( MSVCRT_wchar_t* str, MSVCRT_wchar_t c )
121 MSVCRT_wchar_t* ret = str;
122 while (*str) *str++ = c;
123 return ret;
126 /******************************************************************
127 * _wcsupr_s_l (MSVCRT.@)
129 int CDECL MSVCRT__wcsupr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n,
130 MSVCRT__locale_t locale )
132 MSVCRT_wchar_t* ptr = str;
134 if (!str || !n)
136 if (str) *str = '\0';
137 *MSVCRT__errno() = MSVCRT_EINVAL;
138 return MSVCRT_EINVAL;
141 while (n--)
143 if (!*ptr) return 0;
144 /* FIXME: add locale support */
145 *ptr = toupperW(*ptr);
146 ptr++;
149 /* MSDN claims that the function should return and set errno to
150 * ERANGE, which doesn't seem to be true based on the tests. */
151 *str = '\0';
152 *MSVCRT__errno() = MSVCRT_EINVAL;
153 return MSVCRT_EINVAL;
156 /******************************************************************
157 * _wcsupr_s (MSVCRT.@)
160 INT CDECL MSVCRT__wcsupr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
162 return MSVCRT__wcsupr_s_l( str, n, NULL );
165 /******************************************************************
166 * _wcslwr_s (MSVCRT.@)
168 int CDECL MSVCRT__wcslwr_s( MSVCRT_wchar_t* str, MSVCRT_size_t n )
170 MSVCRT_wchar_t* ptr = str;
172 if (!str || !n)
174 if (str) *str = '\0';
175 *MSVCRT__errno() = MSVCRT_EINVAL;
176 return MSVCRT_EINVAL;
179 while (n--)
181 if (!*ptr) return 0;
182 *ptr = tolowerW(*ptr);
183 ptr++;
186 /* MSDN claims that the function should return and set errno to
187 * ERANGE, which doesn't seem to be true based on the tests. */
188 *str = '\0';
189 *MSVCRT__errno() = MSVCRT_EINVAL;
190 return MSVCRT_EINVAL;
193 /*********************************************************************
194 * _wcstod_l - not exported in native msvcrt
196 double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
197 MSVCRT__locale_t locale)
199 MSVCRT_pthreadlocinfo locinfo;
200 unsigned __int64 d=0, hlp;
201 unsigned fpcontrol;
202 int exp=0, sign=1;
203 const MSVCRT_wchar_t *p;
204 double ret;
205 BOOL found_digit = FALSE;
207 if (!MSVCRT_CHECK_PMT(str != NULL)) return 0;
209 if(!locale)
210 locinfo = get_locinfo();
211 else
212 locinfo = locale->locinfo;
214 p = str;
215 while(isspaceW(*p))
216 p++;
218 if(*p == '-') {
219 sign = -1;
220 p++;
221 } else if(*p == '+')
222 p++;
224 while(isdigitW(*p)) {
225 found_digit = TRUE;
226 hlp = d*10+*(p++)-'0';
227 if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
228 exp++;
229 break;
230 } else
231 d = hlp;
233 while(isdigitW(*p)) {
234 exp++;
235 p++;
237 if(*p == *locinfo->lconv->decimal_point)
238 p++;
240 while(isdigitW(*p)) {
241 found_digit = TRUE;
242 hlp = d*10+*(p++)-'0';
243 if(d>MSVCRT_UI64_MAX/10 || hlp<d)
244 break;
246 d = hlp;
247 exp--;
249 while(isdigitW(*p))
250 p++;
252 if(!found_digit) {
253 if(end)
254 *end = (MSVCRT_wchar_t*)str;
255 return 0.0;
258 if(*p=='e' || *p=='E' || *p=='d' || *p=='D') {
259 int e=0, s=1;
261 p++;
262 if(*p == '-') {
263 s = -1;
264 p++;
265 } else if(*p == '+')
266 p++;
268 if(isdigitW(*p)) {
269 while(isdigitW(*p)) {
270 if(e>INT_MAX/10 || (e=e*10+*p-'0')<0)
271 e = INT_MAX;
272 p++;
274 e *= s;
276 if(exp<0 && e<0 && exp+e>=0) exp = INT_MIN;
277 else if(exp>0 && e>0 && exp+e<0) exp = INT_MAX;
278 else exp += e;
279 } else {
280 if(*p=='-' || *p=='+')
281 p--;
282 p--;
286 fpcontrol = _control87(0, 0);
287 _control87(MSVCRT__EM_DENORMAL|MSVCRT__EM_INVALID|MSVCRT__EM_ZERODIVIDE
288 |MSVCRT__EM_OVERFLOW|MSVCRT__EM_UNDERFLOW|MSVCRT__EM_INEXACT, 0xffffffff);
290 if(exp>0)
291 ret = (double)sign*d*pow(10, exp);
292 else
293 ret = (double)sign*d/pow(10, -exp);
295 _control87(fpcontrol, 0xffffffff);
297 if((d && ret==0.0) || isinf(ret))
298 *MSVCRT__errno() = MSVCRT_ERANGE;
300 if(end)
301 *end = (MSVCRT_wchar_t*)p;
303 return ret;
306 /*********************************************************************
307 * wcsrtombs_l (INTERNAL)
309 static MSVCRT_size_t CDECL MSVCRT_wcsrtombs_l(char *mbstr, const MSVCRT_wchar_t **wcstr,
310 MSVCRT_size_t count, MSVCRT__locale_t locale)
312 MSVCRT_pthreadlocinfo locinfo;
313 MSVCRT_size_t tmp = 0;
314 BOOL used_default;
316 if(!locale)
317 locinfo = get_locinfo();
318 else
319 locinfo = locale->locinfo;
321 if(!mbstr) {
322 tmp = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
323 *wcstr, -1, NULL, 0, NULL, &used_default)-1;
324 if(used_default)
325 return -1;
326 return tmp;
329 while(**wcstr) {
330 char buf[3];
331 MSVCRT_size_t i, size;
333 size = WideCharToMultiByte(locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS,
334 *wcstr, 1, buf, 3, NULL, &used_default);
335 if(used_default)
336 return -1;
337 if(tmp+size > count)
338 return tmp;
340 for(i=0; i<size; i++)
341 mbstr[tmp++] = buf[i];
342 (*wcstr)++;
345 if(tmp < count) {
346 mbstr[tmp] = '\0';
347 *wcstr = NULL;
349 return tmp;
352 /*********************************************************************
353 * _wcstombs_l (MSVCRT.@)
355 MSVCRT_size_t CDECL MSVCRT__wcstombs_l(char *mbstr, const MSVCRT_wchar_t *wcstr,
356 MSVCRT_size_t count, MSVCRT__locale_t locale)
358 return MSVCRT_wcsrtombs_l(mbstr, &wcstr, count, locale);
361 /*********************************************************************
362 * wcstombs (MSVCRT.@)
364 MSVCRT_size_t CDECL MSVCRT_wcstombs(char *mbstr, const MSVCRT_wchar_t *wcstr,
365 MSVCRT_size_t count)
367 return MSVCRT_wcsrtombs_l(mbstr, &wcstr, count, NULL);
370 /*********************************************************************
371 * wcsrtombs (MSVCRT.@)
373 MSVCRT_size_t CDECL MSVCRT_wcsrtombs(char *mbstr, const MSVCRT_wchar_t **wcstr,
374 MSVCRT_size_t count, MSVCRT_mbstate_t *mbstate)
376 if(mbstate)
377 *mbstate = 0;
379 return MSVCRT_wcsrtombs_l(mbstr, wcstr, count, NULL);
382 /*********************************************************************
383 * MSVCRT_wcsrtombs_s_l (INTERNAL)
385 static int MSVCRT_wcsrtombs_s_l(MSVCRT_size_t *ret, char *mbstr,
386 MSVCRT_size_t size, const MSVCRT_wchar_t **wcstr,
387 MSVCRT_size_t count, MSVCRT__locale_t locale)
389 MSVCRT_size_t conv;
391 if(!mbstr && !size && wcstr) {
392 conv = MSVCRT_wcsrtombs_l(NULL, wcstr, 0, locale);
393 if(ret)
394 *ret = conv+1;
395 return 0;
398 if (!MSVCRT_CHECK_PMT(mbstr != NULL)) return MSVCRT_EINVAL;
399 if (size) mbstr[0] = '\0';
400 if (!MSVCRT_CHECK_PMT(wcstr != NULL)) return MSVCRT_EINVAL;
401 if (!MSVCRT_CHECK_PMT(*wcstr != NULL)) return MSVCRT_EINVAL;
403 if(count==MSVCRT__TRUNCATE || size<count)
404 conv = size;
405 else
406 conv = count;
408 conv = MSVCRT_wcsrtombs_l(mbstr, wcstr, conv, locale);
409 if(conv<size)
410 mbstr[conv++] = '\0';
411 else if(conv==size && (count==MSVCRT__TRUNCATE || mbstr[conv-1]=='\0'))
412 mbstr[conv-1] = '\0';
413 else {
414 MSVCRT_INVALID_PMT("mbstr[size] is too small", MSVCRT_ERANGE);
415 if(size)
416 mbstr[0] = '\0';
417 return MSVCRT_ERANGE;
420 if(ret)
421 *ret = conv;
422 return 0;
425 /*********************************************************************
426 * _wcstombs_s_l (MSVCRT.@)
428 int CDECL MSVCRT__wcstombs_s_l(MSVCRT_size_t *ret, char *mbstr,
429 MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr,
430 MSVCRT_size_t count, MSVCRT__locale_t locale)
432 return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, &wcstr,count, locale);
435 /*********************************************************************
436 * wcstombs_s (MSVCRT.@)
438 int CDECL MSVCRT_wcstombs_s(MSVCRT_size_t *ret, char *mbstr,
439 MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr, MSVCRT_size_t count)
441 return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, &wcstr, count, NULL);
444 /*********************************************************************
445 * wcsrtombs_s (MSVCRT.@)
447 int CDECL MSVCRT_wcsrtombs_s(MSVCRT_size_t *ret, char *mbstr, MSVCRT_size_t size,
448 const MSVCRT_wchar_t **wcstr, MSVCRT_size_t count, MSVCRT_mbstate_t *mbstate)
450 if(mbstate)
451 *mbstate = 0;
453 return MSVCRT_wcsrtombs_s_l(ret, mbstr, size, wcstr, count, NULL);
456 /*********************************************************************
457 * wcstod (MSVCRT.@)
459 double CDECL MSVCRT_wcstod(const MSVCRT_wchar_t* lpszStr, MSVCRT_wchar_t** end)
461 return MSVCRT__wcstod_l(lpszStr, end, NULL);
464 /*********************************************************************
465 * _wtof (MSVCRT.@)
467 double CDECL MSVCRT__wtof(const MSVCRT_wchar_t *str)
469 return MSVCRT__wcstod_l(str, NULL, NULL);
472 /*********************************************************************
473 * _wtof_l (MSVCRT.@)
475 double CDECL MSVCRT__wtof_l(const MSVCRT_wchar_t *str, MSVCRT__locale_t locale)
477 return MSVCRT__wcstod_l(str, NULL, locale);
480 /*********************************************************************
481 * arg_clbk_valist (INTERNAL)
483 printf_arg arg_clbk_valist(void *ctx, int arg_pos, int type, __ms_va_list *valist)
485 printf_arg ret;
487 if(type == VT_I8)
488 ret.get_longlong = va_arg(*valist, LONGLONG);
489 else if(type == VT_INT)
490 ret.get_int = va_arg(*valist, int);
491 else if(type == VT_R8)
492 ret.get_double = va_arg(*valist, double);
493 else if(type == VT_PTR)
494 ret.get_ptr = va_arg(*valist, void*);
495 else {
496 ERR("Incorrect type\n");
497 ret.get_int = 0;
500 return ret;
503 /*********************************************************************
504 * arg_clbk_positional (INTERNAL)
506 static printf_arg arg_clbk_positional(void *ctx, int pos, int type, __ms_va_list *valist)
508 printf_arg *args = ctx;
509 return args[pos];
512 /*********************************************************************
513 * _vsnprintf (MSVCRT.@)
515 int CDECL MSVCRT_vsnprintf( char *str, MSVCRT_size_t len,
516 const char *format, __ms_va_list valist )
518 static const char nullbyte = '\0';
519 struct _str_ctx_a ctx = {len, str};
520 int ret;
522 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, NULL, FALSE, FALSE,
523 arg_clbk_valist, NULL, &valist);
524 puts_clbk_str_a(&ctx, 1, &nullbyte);
525 return ret;
528 /*********************************************************************
529 * _vsnprintf_l (MSVCRT.@)
531 int CDECL MSVCRT_vsnprintf_l( char *str, MSVCRT_size_t len, const char *format,
532 MSVCRT__locale_t locale, __ms_va_list valist )
534 static const char nullbyte = '\0';
535 struct _str_ctx_a ctx = {len, str};
536 int ret;
538 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, FALSE,
539 arg_clbk_valist, NULL, &valist);
540 puts_clbk_str_a(&ctx, 1, &nullbyte);
541 return ret;
544 /*********************************************************************
545 * _vsnprintf_s_l (MSVCRT.@)
547 int CDECL MSVCRT_vsnprintf_s_l( char *str, MSVCRT_size_t sizeOfBuffer,
548 MSVCRT_size_t count, const char *format,
549 MSVCRT__locale_t locale, __ms_va_list valist )
551 static const char nullbyte = '\0';
552 struct _str_ctx_a ctx;
553 int len, ret;
555 if(sizeOfBuffer<count+1 || count==-1)
556 len = sizeOfBuffer;
557 else
558 len = count+1;
560 ctx.len = len;
561 ctx.buf = str;
562 ret = pf_printf_a(puts_clbk_str_a, &ctx, format, locale, FALSE, TRUE,
563 arg_clbk_valist, NULL, &valist);
564 puts_clbk_str_a(&ctx, 1, &nullbyte);
566 if(ret<0 || ret==len) {
567 if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
568 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE);
569 memset(str, 0, sizeOfBuffer);
570 } else
571 str[len-1] = '\0';
573 return -1;
576 return ret;
579 /*********************************************************************
580 * _vsnprintf_s (MSVCRT.@)
582 int CDECL MSVCRT_vsnprintf_s( char *str, MSVCRT_size_t sizeOfBuffer,
583 MSVCRT_size_t count, const char *format, __ms_va_list valist )
585 return MSVCRT_vsnprintf_s_l(str,sizeOfBuffer, count, format, NULL, valist);
588 /*********************************************************************
589 * vsprintf (MSVCRT.@)
591 int CDECL MSVCRT_vsprintf( char *str, const char *format, __ms_va_list valist)
593 return MSVCRT_vsnprintf(str, INT_MAX, format, valist);
596 /*********************************************************************
597 * vsprintf_s (MSVCRT.@)
599 int CDECL MSVCRT_vsprintf_s( char *str, MSVCRT_size_t num, const char *format, __ms_va_list valist)
601 return MSVCRT_vsnprintf(str, num, format, valist);
604 /*********************************************************************
605 * _vscprintf (MSVCRT.@)
607 int CDECL MSVCRT__vscprintf( const char *format, __ms_va_list valist )
609 return MSVCRT_vsnprintf( NULL, INT_MAX, format, valist );
612 /*********************************************************************
613 * _snprintf (MSVCRT.@)
615 int CDECL MSVCRT__snprintf(char *str, unsigned int len, const char *format, ...)
617 int retval;
618 __ms_va_list valist;
619 __ms_va_start(valist, format);
620 retval = MSVCRT_vsnprintf(str, len, format, valist);
621 __ms_va_end(valist);
622 return retval;
625 /*********************************************************************
626 * _snprintf_s (MSVCRT.@)
628 int CDECL MSVCRT__snprintf_s(char *str, unsigned int len, unsigned int count,
629 const char *format, ...)
631 int retval;
632 __ms_va_list valist;
633 __ms_va_start(valist, format);
634 retval = MSVCRT_vsnprintf_s_l(str, len, count, format, NULL, valist);
635 __ms_va_end(valist);
636 return retval;
639 /*********************************************************************
640 * _scprintf (MSVCRT.@)
642 int CDECL MSVCRT__scprintf(const char *format, ...)
644 int retval;
645 __ms_va_list valist;
646 __ms_va_start(valist, format);
647 retval = MSVCRT__vscprintf(format, valist);
648 __ms_va_end(valist);
649 return retval;
652 /*********************************************************************
653 * _vsnwprintf (MSVCRT.@)
655 int CDECL MSVCRT_vsnwprintf(MSVCRT_wchar_t *str, MSVCRT_size_t len,
656 const MSVCRT_wchar_t *format, __ms_va_list valist)
658 static const MSVCRT_wchar_t nullbyte = '\0';
659 struct _str_ctx_w ctx = {len, str};
660 int ret;
662 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, NULL, FALSE, FALSE,
663 arg_clbk_valist, NULL, &valist);
664 puts_clbk_str_w(&ctx, 1, &nullbyte);
665 return ret;
668 /*********************************************************************
669 * _vsnwprintf_l (MSVCRT.@)
671 int CDECL MSVCRT_vsnwprintf_l(MSVCRT_wchar_t *str, MSVCRT_size_t len,
672 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale,
673 __ms_va_list valist)
675 static const MSVCRT_wchar_t nullbyte = '\0';
676 struct _str_ctx_w ctx = {len, str};
677 int ret;
679 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, FALSE,
680 arg_clbk_valist, NULL, &valist);
681 puts_clbk_str_w(&ctx, 1, &nullbyte);
682 return ret;
685 /*********************************************************************
686 * _vswprintf_p_l (MSVCRT.@)
688 int CDECL MSVCRT_vswprintf_p_l(MSVCRT_wchar_t *buffer, MSVCRT_size_t length,
689 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args)
691 static const MSVCRT_wchar_t nullbyte = '\0';
692 printf_arg args_ctx[MSVCRT__ARGMAX+1];
693 struct _str_ctx_w puts_ctx = {length, buffer};
694 int ret;
696 memset(args_ctx, 0, sizeof(args_ctx));
698 ret = create_positional_ctx_w(args_ctx, format, args);
699 if(ret < 0) {
700 MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
701 *MSVCRT__errno() = MSVCRT_EINVAL;
702 return ret;
703 } else if(ret == 0)
704 ret = pf_printf_w(puts_clbk_str_w, &puts_ctx, format, locale, FALSE, TRUE,
705 arg_clbk_valist, NULL, &args);
706 else
707 ret = pf_printf_w(puts_clbk_str_w, &puts_ctx, format, locale, TRUE, TRUE,
708 arg_clbk_positional, args_ctx, NULL);
710 puts_clbk_str_w(&puts_ctx, 1, &nullbyte);
711 return ret;
714 /*********************************************************************
715 * _vsnwprintf_s_l (MSVCRT.@)
717 int CDECL MSVCRT_vsnwprintf_s_l( MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
718 MSVCRT_size_t count, const MSVCRT_wchar_t *format,
719 MSVCRT__locale_t locale, __ms_va_list valist)
721 static const MSVCRT_wchar_t nullbyte = '\0';
722 struct _str_ctx_w ctx;
723 int len, ret;
725 len = sizeOfBuffer;
726 if(count!=-1 && len>count+1)
727 len = count+1;
729 ctx.len = len;
730 ctx.buf = str;
731 ret = pf_printf_w(puts_clbk_str_w, &ctx, format, locale, FALSE, TRUE,
732 arg_clbk_valist, NULL, &valist);
733 puts_clbk_str_w(&ctx, 1, &nullbyte);
735 if(ret<0 || ret==len) {
736 if(count!=MSVCRT__TRUNCATE && count>sizeOfBuffer) {
737 MSVCRT_INVALID_PMT("str[sizeOfBuffer] is too small", MSVCRT_ERANGE);
738 memset(str, 0, sizeOfBuffer*sizeof(MSVCRT_wchar_t));
739 } else
740 str[len-1] = '\0';
742 return -1;
745 return ret;
748 /*********************************************************************
749 * _vsnwprintf_s (MSVCRT.@)
751 int CDECL MSVCRT_vsnwprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t sizeOfBuffer,
752 MSVCRT_size_t count, const MSVCRT_wchar_t *format, __ms_va_list valist)
754 return MSVCRT_vsnwprintf_s_l(str, sizeOfBuffer, count,
755 format, NULL, valist);
758 /*********************************************************************
759 * _snwprintf (MSVCRT.@)
761 int CDECL MSVCRT__snwprintf( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format, ...)
763 int retval;
764 __ms_va_list valist;
765 __ms_va_start(valist, format);
766 retval = MSVCRT_vsnwprintf(str, len, format, valist);
767 __ms_va_end(valist);
768 return retval;
771 /*********************************************************************
772 * _snwprintf_l (MSVCRT.@)
774 int CDECL MSVCRT__snwprintf_l( MSVCRT_wchar_t *str, unsigned int len, const MSVCRT_wchar_t *format,
775 MSVCRT__locale_t locale, ...)
777 int retval;
778 __ms_va_list valist;
779 __ms_va_start(valist, locale);
780 retval = MSVCRT_vsnwprintf_l(str, len, format, locale, valist);
781 __ms_va_end(valist);
782 return retval;
785 /*********************************************************************
786 * _snwprintf_s (MSVCRT.@)
788 int CDECL MSVCRT__snwprintf_s( MSVCRT_wchar_t *str, unsigned int len, unsigned int count,
789 const MSVCRT_wchar_t *format, ...)
791 int retval;
792 __ms_va_list valist;
793 __ms_va_start(valist, format);
794 retval = MSVCRT_vsnwprintf_s_l(str, len, count, format, NULL, valist);
795 __ms_va_end(valist);
796 return retval;
799 /*********************************************************************
800 * sprintf (MSVCRT.@)
802 int CDECL MSVCRT_sprintf( char *str, const char *format, ... )
804 __ms_va_list ap;
805 int r;
807 __ms_va_start( ap, format );
808 r = MSVCRT_vsnprintf( str, INT_MAX, format, ap );
809 __ms_va_end( ap );
810 return r;
813 /*********************************************************************
814 * sprintf_s (MSVCRT.@)
816 int CDECL MSVCRT_sprintf_s( char *str, MSVCRT_size_t num, const char *format, ... )
818 __ms_va_list ap;
819 int r;
821 __ms_va_start( ap, format );
822 r = MSVCRT_vsnprintf( str, num, format, ap );
823 __ms_va_end( ap );
824 return r;
827 /*********************************************************************
828 * _scwprintf (MSVCRT.@)
830 int CDECL MSVCRT__scwprintf( const MSVCRT_wchar_t *format, ... )
832 __ms_va_list ap;
833 int r;
835 __ms_va_start( ap, format );
836 r = MSVCRT_vsnwprintf( NULL, INT_MAX, format, ap );
837 __ms_va_end( ap );
838 return r;
841 /*********************************************************************
842 * swprintf (MSVCRT.@)
844 int CDECL MSVCRT_swprintf( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format, ... )
846 __ms_va_list ap;
847 int r;
849 __ms_va_start( ap, format );
850 r = MSVCRT_vsnwprintf( str, INT_MAX, format, ap );
851 __ms_va_end( ap );
852 return r;
855 /*********************************************************************
856 * swprintf_s (MSVCRT.@)
858 int CDECL MSVCRT_swprintf_s(MSVCRT_wchar_t *str, MSVCRT_size_t numberOfElements,
859 const MSVCRT_wchar_t *format, ... )
861 __ms_va_list ap;
862 int r;
864 __ms_va_start(ap, format);
865 r = MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, ap);
866 __ms_va_end(ap);
868 return r;
871 /*********************************************************************
872 * _vswprintf (MSVCRT.@)
874 int CDECL MSVCRT_vswprintf( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format, __ms_va_list args )
876 return MSVCRT_vsnwprintf( str, INT_MAX, format, args );
879 /*********************************************************************
880 * _vswprintf (MSVCRT.@)
882 int CDECL MSVCRT_vswprintf_l( MSVCRT_wchar_t* str, const MSVCRT_wchar_t* format,
883 MSVCRT__locale_t locale, __ms_va_list args )
885 return MSVCRT_vsnwprintf_l( str, INT_MAX, format, locale, args );
888 /*********************************************************************
889 * _vscwprintf (MSVCRT.@)
891 int CDECL MSVCRT__vscwprintf( const MSVCRT_wchar_t *format, __ms_va_list args )
893 return MSVCRT_vsnwprintf( NULL, INT_MAX, format, args );
896 /*********************************************************************
897 * _vscwprintf_l (MSVCRT.@)
899 int CDECL MSVCRT__vscwprintf_l( const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args )
901 return MSVCRT_vsnwprintf_l( NULL, INT_MAX, format, locale, args );
904 /*********************************************************************
905 * _vscwprintf_p_l (MSVCRT.@)
907 int CDECL MSVCRT__vscwprintf_p_l( const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list args )
909 return MSVCRT_vswprintf_p_l( NULL, INT_MAX, format, locale, args );
912 /*********************************************************************
913 * vswprintf_s (MSVCRT.@)
915 int CDECL MSVCRT_vswprintf_s(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
916 const MSVCRT_wchar_t* format, __ms_va_list args)
918 return MSVCRT_vsnwprintf_s(str, numberOfElements, INT_MAX, format, args );
921 /*********************************************************************
922 * _vswprintf_s_l (MSVCRT.@)
924 int CDECL MSVCRT_vswprintf_s_l(MSVCRT_wchar_t* str, MSVCRT_size_t numberOfElements,
925 const MSVCRT_wchar_t* format, MSVCRT__locale_t locale, __ms_va_list args)
927 return MSVCRT_vsnwprintf_s_l(str, numberOfElements, INT_MAX,
928 format, locale, args );
931 /*********************************************************************
932 * _vsprintf_p_l (MSVCRT.@)
934 int CDECL MSVCRT_vsprintf_p_l(char *buffer, MSVCRT_size_t length, const char *format,
935 MSVCRT__locale_t locale, __ms_va_list args)
937 static const char nullbyte = '\0';
938 printf_arg args_ctx[MSVCRT__ARGMAX+1];
939 struct _str_ctx_a puts_ctx = {length, buffer};
940 int ret;
942 memset(args_ctx, 0, sizeof(args_ctx));
944 ret = create_positional_ctx_a(args_ctx, format, args);
945 if(ret < 0) {
946 MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
947 *MSVCRT__errno() = MSVCRT_EINVAL;
948 return ret;
949 } else if(ret == 0)
950 ret = pf_printf_a(puts_clbk_str_a, &puts_ctx, format, locale, FALSE, TRUE,
951 arg_clbk_valist, NULL, &args);
952 else
953 ret = pf_printf_a(puts_clbk_str_a, &puts_ctx, format, locale, TRUE, TRUE,
954 arg_clbk_positional, args_ctx, NULL);
956 puts_clbk_str_a(&puts_ctx, 1, &nullbyte);
957 return ret;
960 /*********************************************************************
961 * _vsprintf_p (MSVCRT.@)
963 int CDECL MSVCRT_vsprintf_p(char *buffer, MSVCRT_size_t length,
964 const char *format, __ms_va_list args)
966 return MSVCRT_vsprintf_p_l(buffer, length, format, NULL, args);
969 /*********************************************************************
970 * _sprintf_p_l (MSVCRT.@)
972 int CDECL MSVCRT_sprintf_p_l(char *buffer, MSVCRT_size_t length,
973 const char *format, MSVCRT__locale_t locale, ...)
975 __ms_va_list valist;
976 int r;
978 __ms_va_start(valist, locale);
979 r = MSVCRT_vsprintf_p_l(buffer, length, format, locale, valist);
980 __ms_va_end(valist);
982 return r;
985 /*********************************************************************
986 * _swprintf_p_l (MSVCRT.@)
988 int CDECL MSVCRT_swprintf_p_l(MSVCRT_wchar_t *buffer, MSVCRT_size_t length,
989 const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, ...)
991 __ms_va_list valist;
992 int r;
994 __ms_va_start(valist, locale);
995 r = MSVCRT_vswprintf_p_l(buffer, length, format, locale, valist);
996 __ms_va_end(valist);
998 return r;
1001 /*********************************************************************
1002 * wcscoll (MSVCRT.@)
1004 int CDECL MSVCRT_wcscoll( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str2 )
1006 /* FIXME: handle collates */
1007 return strcmpW( str1, str2 );
1010 /*********************************************************************
1011 * wcspbrk (MSVCRT.@)
1013 MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wchar_t* accept )
1015 const MSVCRT_wchar_t* p;
1016 while (*str)
1018 for (p = accept; *p; p++) if (*p == *str) return (MSVCRT_wchar_t*)str;
1019 str++;
1021 return NULL;
1024 /*********************************************************************
1025 * wcstok_s (MSVCRT.@)
1027 MSVCRT_wchar_t * CDECL wcstok_s( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim,
1028 MSVCRT_wchar_t **next_token )
1030 MSVCRT_wchar_t *ret;
1032 if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
1033 if (!MSVCRT_CHECK_PMT(next_token != NULL)) return NULL;
1034 if (!MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL)) return NULL;
1036 if (!str) str = *next_token;
1038 while (*str && strchrW( delim, *str )) str++;
1039 if (!*str) return NULL;
1040 ret = str++;
1041 while (*str && !strchrW( delim, *str )) str++;
1042 if (*str) *str++ = 0;
1043 *next_token = str;
1044 return ret;
1047 /*********************************************************************
1048 * wcstok (MSVCRT.@)
1050 MSVCRT_wchar_t * CDECL MSVCRT_wcstok( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim )
1052 return wcstok_s(str, delim, &msvcrt_get_thread_data()->wcstok_next);
1055 /*********************************************************************
1056 * wctob (MSVCRT.@)
1058 INT CDECL MSVCRT_wctob( MSVCRT_wint_t wchar )
1060 char out;
1061 BOOL error;
1062 UINT codepage = get_locinfo()->lc_codepage;
1064 if(!codepage) {
1065 if (wchar < 0xff)
1066 return (signed char)wchar;
1067 else
1068 return MSVCRT_EOF;
1069 } else if(WideCharToMultiByte( codepage, 0, &wchar, 1, &out, 1, NULL, &error ) && !error)
1070 return (INT)out;
1071 return MSVCRT_EOF;
1074 /*********************************************************************
1075 * wctomb (MSVCRT.@)
1077 INT CDECL MSVCRT_wctomb( char *dst, MSVCRT_wchar_t ch )
1079 return WideCharToMultiByte( get_locinfo()->lc_codepage, 0, &ch, 1, dst, 6, NULL, NULL );
1082 /*********************************************************************
1083 * iswalnum (MSVCRT.@)
1085 INT CDECL MSVCRT_iswalnum( MSVCRT_wchar_t wc )
1087 return isalnumW( wc );
1090 /*********************************************************************
1091 * iswalpha (MSVCRT.@)
1093 INT CDECL MSVCRT_iswalpha( MSVCRT_wchar_t wc )
1095 return isalphaW( wc );
1098 /*********************************************************************
1099 * iswalpha_l (MSVCRT.@)
1101 INT CDECL MSVCRT__iswalpha_l( MSVCRT_wchar_t wc, MSVCRT__locale_t locale )
1103 return isalphaW( wc );
1106 /*********************************************************************
1107 * iswcntrl (MSVCRT.@)
1109 INT CDECL MSVCRT_iswcntrl( MSVCRT_wchar_t wc )
1111 return iscntrlW( wc );
1114 /*********************************************************************
1115 * iswdigit (MSVCRT.@)
1117 INT CDECL MSVCRT_iswdigit( MSVCRT_wchar_t wc )
1119 return isdigitW( wc );
1122 /*********************************************************************
1123 * _iswdigit_l (MSVCRT.@)
1125 INT CDECL MSVCRT__iswdigit_l( MSVCRT_wchar_t wc, MSVCRT__locale_t locale )
1127 return isdigitW( wc );
1130 /*********************************************************************
1131 * iswgraph (MSVCRT.@)
1133 INT CDECL MSVCRT_iswgraph( MSVCRT_wchar_t wc )
1135 return isgraphW( wc );
1138 /*********************************************************************
1139 * iswlower (MSVCRT.@)
1141 INT CDECL MSVCRT_iswlower( MSVCRT_wchar_t wc )
1143 return islowerW( wc );
1146 /*********************************************************************
1147 * iswprint (MSVCRT.@)
1149 INT CDECL MSVCRT_iswprint( MSVCRT_wchar_t wc )
1151 return isprintW( wc );
1154 /*********************************************************************
1155 * iswpunct (MSVCRT.@)
1157 INT CDECL MSVCRT_iswpunct( MSVCRT_wchar_t wc )
1159 return ispunctW( wc );
1162 /*********************************************************************
1163 * iswspace (MSVCRT.@)
1165 INT CDECL MSVCRT_iswspace( MSVCRT_wchar_t wc )
1167 return isspaceW( wc );
1170 /*********************************************************************
1171 * iswupper (MSVCRT.@)
1173 INT CDECL MSVCRT_iswupper( MSVCRT_wchar_t wc )
1175 return isupperW( wc );
1178 /*********************************************************************
1179 * iswxdigit (MSVCRT.@)
1181 INT CDECL MSVCRT_iswxdigit( MSVCRT_wchar_t wc )
1183 return isxdigitW( wc );
1186 /*********************************************************************
1187 * wcscpy_s (MSVCRT.@)
1189 INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc)
1191 MSVCRT_size_t size = 0;
1193 if(!wcDest || !numElement)
1194 return MSVCRT_EINVAL;
1196 wcDest[0] = 0;
1198 if(!wcSrc)
1200 return MSVCRT_EINVAL;
1203 size = strlenW(wcSrc) + 1;
1205 if(size > numElement)
1207 return MSVCRT_ERANGE;
1210 memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
1212 return 0;
1215 /******************************************************************
1216 * wcsncpy_s (MSVCRT.@)
1218 INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, const MSVCRT_wchar_t *wcSrc,
1219 MSVCRT_size_t count )
1221 WCHAR *p = wcDest;
1222 BOOL truncate = (count == MSVCRT__TRUNCATE);
1224 if(!wcDest && !numElement && !count)
1225 return 0;
1227 if (!wcDest || !numElement)
1228 return MSVCRT_EINVAL;
1230 if (!wcSrc)
1232 *wcDest = 0;
1233 return count ? MSVCRT_EINVAL : 0;
1236 while (numElement && count && *wcSrc)
1238 *p++ = *wcSrc++;
1239 numElement--;
1240 count--;
1242 if (!numElement && truncate)
1244 *(p-1) = 0;
1245 return MSVCRT_STRUNCATE;
1247 else if (!numElement)
1249 *wcDest = 0;
1250 return MSVCRT_ERANGE;
1253 *p = 0;
1254 return 0;
1257 /******************************************************************
1258 * wcscat_s (MSVCRT.@)
1261 INT CDECL MSVCRT_wcscat_s(MSVCRT_wchar_t* dst, MSVCRT_size_t elem, const MSVCRT_wchar_t* src)
1263 MSVCRT_wchar_t* ptr = dst;
1265 if (!dst || elem == 0) return MSVCRT_EINVAL;
1266 if (!src)
1268 dst[0] = '\0';
1269 return MSVCRT_EINVAL;
1272 /* seek to end of dst string (or elem if no end of string is found */
1273 while (ptr < dst + elem && *ptr != '\0') ptr++;
1274 while (ptr < dst + elem)
1276 if ((*ptr++ = *src++) == '\0') return 0;
1278 /* not enough space */
1279 dst[0] = '\0';
1280 return MSVCRT_ERANGE;
1283 /*********************************************************************
1284 * wcsncat_s (MSVCRT.@)
1287 INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
1288 const MSVCRT_wchar_t *src, MSVCRT_size_t count)
1290 MSVCRT_size_t srclen;
1291 MSVCRT_wchar_t dststart;
1292 INT ret = 0;
1294 if (!MSVCRT_CHECK_PMT(dst != NULL)) return MSVCRT_EINVAL;
1295 if (!MSVCRT_CHECK_PMT(elem > 0)) return MSVCRT_EINVAL;
1296 if (!MSVCRT_CHECK_PMT(src != NULL || count == 0)) return MSVCRT_EINVAL;
1298 if (count == 0)
1299 return 0;
1301 for (dststart = 0; dststart < elem; dststart++)
1303 if (dst[dststart] == '\0')
1304 break;
1306 if (dststart == elem)
1308 MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", MSVCRT_EINVAL);
1309 return MSVCRT_EINVAL;
1312 if (count == MSVCRT__TRUNCATE)
1314 srclen = strlenW(src);
1315 if (srclen >= (elem - dststart))
1317 srclen = elem - dststart - 1;
1318 ret = MSVCRT_STRUNCATE;
1321 else
1322 srclen = min(strlenW(src), count);
1323 if (srclen < (elem - dststart))
1325 memcpy(&dst[dststart], src, srclen*sizeof(MSVCRT_wchar_t));
1326 dst[dststart+srclen] = '\0';
1327 return ret;
1329 MSVCRT_INVALID_PMT("dst[elem] is too small", MSVCRT_ERANGE);
1330 dst[0] = '\0';
1331 return MSVCRT_ERANGE;
1334 /*********************************************************************
1335 * _wcstoi64_l (MSVCRT.@)
1337 * FIXME: locale parameter is ignored
1339 __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
1340 MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
1342 BOOL negative = FALSE;
1343 __int64 ret = 0;
1345 TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
1347 if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
1348 if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
1349 if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
1351 while(isspaceW(*nptr)) nptr++;
1353 if(*nptr == '-') {
1354 negative = TRUE;
1355 nptr++;
1356 } else if(*nptr == '+')
1357 nptr++;
1359 if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
1360 base = 16;
1361 nptr += 2;
1364 if(base == 0) {
1365 if(*nptr=='0')
1366 base = 8;
1367 else
1368 base = 10;
1371 while(*nptr) {
1372 char cur = tolowerW(*nptr);
1373 int v;
1375 if(isdigitW(cur)) {
1376 if(cur >= '0'+base)
1377 break;
1378 v = cur-'0';
1379 } else {
1380 if(cur<'a' || cur>='a'+base-10)
1381 break;
1382 v = cur-'a'+10;
1385 if(negative)
1386 v = -v;
1388 nptr++;
1390 if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
1391 ret = MSVCRT_I64_MAX;
1392 *MSVCRT__errno() = MSVCRT_ERANGE;
1393 } else if(negative && (ret<MSVCRT_I64_MIN/base || ret*base<MSVCRT_I64_MIN-v)) {
1394 ret = MSVCRT_I64_MIN;
1395 *MSVCRT__errno() = MSVCRT_ERANGE;
1396 } else
1397 ret = ret*base + v;
1400 if(endptr)
1401 *endptr = (MSVCRT_wchar_t*)nptr;
1403 return ret;
1406 /*********************************************************************
1407 * _wcstoi64 (MSVCRT.@)
1409 __int64 CDECL MSVCRT__wcstoi64(const MSVCRT_wchar_t *nptr,
1410 MSVCRT_wchar_t **endptr, int base)
1412 return MSVCRT__wcstoi64_l(nptr, endptr, base, NULL);
1415 /*********************************************************************
1416 * _wcstoui64_l (MSVCRT.@)
1418 * FIXME: locale parameter is ignored
1420 unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
1421 MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
1423 BOOL negative = FALSE;
1424 unsigned __int64 ret = 0;
1426 TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
1428 if (!MSVCRT_CHECK_PMT(nptr != NULL)) return 0;
1429 if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
1430 if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
1432 while(isspaceW(*nptr)) nptr++;
1434 if(*nptr == '-') {
1435 negative = TRUE;
1436 nptr++;
1437 } else if(*nptr == '+')
1438 nptr++;
1440 if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
1441 base = 16;
1442 nptr += 2;
1445 if(base == 0) {
1446 if(*nptr=='0')
1447 base = 8;
1448 else
1449 base = 10;
1452 while(*nptr) {
1453 char cur = tolowerW(*nptr);
1454 int v;
1456 if(isdigit(cur)) {
1457 if(cur >= '0'+base)
1458 break;
1459 v = *nptr-'0';
1460 } else {
1461 if(cur<'a' || cur>='a'+base-10)
1462 break;
1463 v = cur-'a'+10;
1466 nptr++;
1468 if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
1469 ret = MSVCRT_UI64_MAX;
1470 *MSVCRT__errno() = MSVCRT_ERANGE;
1471 } else
1472 ret = ret*base + v;
1475 if(endptr)
1476 *endptr = (MSVCRT_wchar_t*)nptr;
1478 return negative ? -ret : ret;
1481 /*********************************************************************
1482 * _wcstoui64 (MSVCRT.@)
1484 unsigned __int64 CDECL MSVCRT__wcstoui64(const MSVCRT_wchar_t *nptr,
1485 MSVCRT_wchar_t **endptr, int base)
1487 return MSVCRT__wcstoui64_l(nptr, endptr, base, NULL);
1490 /******************************************************************
1491 * wcsnlen (MSVCRT.@)
1493 MSVCRT_size_t CDECL MSVCRT_wcsnlen(const MSVCRT_wchar_t *s, MSVCRT_size_t maxlen)
1495 MSVCRT_size_t i;
1497 for (i = 0; i < maxlen; i++)
1498 if (!s[i]) break;
1499 return i;
1502 /*********************************************************************
1503 * _towupper_l (MSVCRT.@)
1505 int CDECL MSVCRT__towupper_l(MSVCRT_wint_t c, MSVCRT__locale_t locale)
1507 return toupperW(c);
1510 /*********************************************************************
1511 * _towlower_l (MSVCRT.@)
1513 int CDECL MSVCRT__towlower_l(MSVCRT_wint_t c, MSVCRT__locale_t locale)
1515 return tolowerW(c);