wined3d: Correctly destroy the adapter on format initialization failure in no3d mode.
[wine/zf.git] / dlls / ntdll / wcstring.c
blob393d5af8c2b47363fdf997204b95cd2a56f5ec62
1 /*
2 * NTDLL wide-char functions
4 * Copyright 2000 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
6 * Copyright 2003 Thomas Mertes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "winternl.h"
33 #include "ntdll_misc.h"
35 static const unsigned short wctypes[256] =
37 /* 00 */
38 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
39 0x0020, 0x0068, 0x0028, 0x0028, 0x0028, 0x0028, 0x0020, 0x0020,
40 /* 10 */
41 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
42 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
43 /* 20 */
44 0x0048, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
45 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
46 /* 30 */
47 0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084,
48 0x0084, 0x0084, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
49 /* 40 */
50 0x0010, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0101,
51 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
52 /* 50 */
53 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
54 0x0101, 0x0101, 0x0101, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
55 /* 60 */
56 0x0010, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0102,
57 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
58 /* 70 */
59 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
60 0x0102, 0x0102, 0x0102, 0x0010, 0x0010, 0x0010, 0x0010, 0x0020,
61 /* 80 */
62 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
63 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
64 /* 90 */
65 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
66 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
67 /* a0 */
68 0x0048, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
69 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
70 /* b0 */
71 0x0010, 0x0010, 0x0014, 0x0014, 0x0010, 0x0010, 0x0010, 0x0010,
72 0x0010, 0x0014, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
73 /* c0 */
74 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
75 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
76 /* d0 */
77 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0010,
78 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0102,
79 /* e0 */
80 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
81 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
82 /* f0 */
83 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0010,
84 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102
88 /*********************************************************************
89 * _wcsicmp (NTDLL.@)
91 int __cdecl _wcsicmp( LPCWSTR str1, LPCWSTR str2 )
93 for (;;)
95 WCHAR ch1 = (*str1 >= 'A' && *str1 <= 'Z') ? *str1 + 32 : *str1;
96 WCHAR ch2 = (*str2 >= 'A' && *str2 <= 'Z') ? *str2 + 32 : *str2;
97 if (ch1 != ch2 || !*str1) return ch1 - ch2;
98 str1++;
99 str2++;
104 /*********************************************************************
105 * _wcslwr (NTDLL.@)
107 LPWSTR __cdecl _wcslwr( LPWSTR str )
109 WCHAR *ret = str;
111 while (*str)
113 WCHAR ch = *str;
114 if (ch >= 'A' && ch <= 'Z') ch += 32;
115 *str++ = ch;
117 return ret;
121 /*********************************************************************
122 * _wcsnicmp (NTDLL.@)
124 int __cdecl _wcsnicmp( LPCWSTR str1, LPCWSTR str2, size_t n )
126 int ret = 0;
127 for ( ; n > 0; n--, str1++, str2++)
129 WCHAR ch1 = (*str1 >= 'A' && *str1 <= 'Z') ? *str1 + 32 : *str1;
130 WCHAR ch2 = (*str2 >= 'A' && *str2 <= 'Z') ? *str2 + 32 : *str2;
131 if ((ret = ch1 - ch2) || !*str1) break;
133 return ret;
137 /*********************************************************************
138 * _wcsupr (NTDLL.@)
140 LPWSTR __cdecl _wcsupr( LPWSTR str )
142 WCHAR *ret = str;
144 while (*str)
146 WCHAR ch = *str;
147 if (ch >= 'a' && ch <= 'z') ch -= 32;
148 *str++ = ch;
150 return ret;
154 /***********************************************************************
155 * wcscpy (NTDLL.@)
157 LPWSTR __cdecl wcscpy( LPWSTR dst, LPCWSTR src )
159 WCHAR *p = dst;
160 while ((*p++ = *src++));
161 return dst;
165 /***********************************************************************
166 * wcslen (NTDLL.@)
168 size_t __cdecl wcslen( LPCWSTR str )
170 const WCHAR *s = str;
171 while (*s) s++;
172 return s - str;
176 /***********************************************************************
177 * wcscat (NTDLL.@)
179 LPWSTR __cdecl wcscat( LPWSTR dst, LPCWSTR src )
181 wcscpy( dst + wcslen(dst), src );
182 return dst;
186 /*********************************************************************
187 * wcschr (NTDLL.@)
189 LPWSTR __cdecl wcschr( LPCWSTR str, WCHAR ch )
191 do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
192 return NULL;
196 /*********************************************************************
197 * wcscmp (NTDLL.@)
199 int __cdecl wcscmp( LPCWSTR str1, LPCWSTR str2 )
201 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
202 return *str1 - *str2;
206 /*********************************************************************
207 * wcscspn (NTDLL.@)
209 size_t __cdecl wcscspn( LPCWSTR str, LPCWSTR reject )
211 const WCHAR *ptr;
212 for (ptr = str; *ptr; ptr++) if (wcschr( reject, *ptr )) break;
213 return ptr - str;
217 /*********************************************************************
218 * wcsncat (NTDLL.@)
220 LPWSTR __cdecl wcsncat( LPWSTR s1, LPCWSTR s2, size_t n )
222 LPWSTR ret = s1;
223 while (*s1) s1++;
224 while (n-- > 0) if (!(*s1++ = *s2++)) return ret;
225 *s1 = 0;
226 return ret;
230 /*********************************************************************
231 * wcsncmp (NTDLL.@)
233 int __cdecl wcsncmp( LPCWSTR str1, LPCWSTR str2, size_t n )
235 if (n <= 0) return 0;
236 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
237 return *str1 - *str2;
241 /*********************************************************************
242 * wcsncpy (NTDLL.@)
244 LPWSTR __cdecl wcsncpy( LPWSTR s1, LPCWSTR s2, size_t n )
246 WCHAR *ret = s1;
247 while (n-- > 0) if (!(*s1++ = *s2++)) break;
248 while (n-- > 0) *s1++ = 0;
249 return ret;
253 /*********************************************************************
254 * wcspbrk (NTDLL.@)
256 LPWSTR __cdecl wcspbrk( LPCWSTR str, LPCWSTR accept )
258 for ( ; *str; str++) if (wcschr( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
259 return NULL;
263 /*********************************************************************
264 * wcsrchr (NTDLL.@)
266 LPWSTR __cdecl wcsrchr( LPCWSTR str, WCHAR ch )
268 WCHAR *ret = NULL;
269 do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
270 return ret;
274 /*********************************************************************
275 * wcsspn (NTDLL.@)
277 size_t __cdecl wcsspn( LPCWSTR str, LPCWSTR accept )
279 const WCHAR *ptr;
280 for (ptr = str; *ptr; ptr++) if (!wcschr( accept, *ptr )) break;
281 return ptr - str;
285 /*********************************************************************
286 * wcsstr (NTDLL.@)
288 LPWSTR __cdecl wcsstr( LPCWSTR str, LPCWSTR sub )
290 while (*str)
292 const WCHAR *p1 = str, *p2 = sub;
293 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
294 if (!*p2) return (WCHAR *)str;
295 str++;
297 return NULL;
301 /*********************************************************************
302 * wcstok (NTDLL.@)
304 LPWSTR __cdecl wcstok( LPWSTR str, LPCWSTR delim )
306 static LPWSTR next = NULL;
307 LPWSTR ret;
309 if (!str)
310 if (!(str = next)) return NULL;
312 while (*str && wcschr( delim, *str )) str++;
313 if (!*str) return NULL;
314 ret = str++;
315 while (*str && !wcschr( delim, *str )) str++;
316 if (*str) *str++ = 0;
317 next = str;
318 return ret;
322 /*********************************************************************
323 * wcstombs (NTDLL.@)
325 size_t __cdecl wcstombs( char *dst, const WCHAR *src, size_t n )
327 DWORD len;
329 if (!dst)
331 RtlUnicodeToMultiByteSize( &len, src, wcslen(src) * sizeof(WCHAR) );
332 return len;
334 else
336 if (n <= 0) return 0;
337 RtlUnicodeToMultiByteN( dst, n, &len, src, wcslen(src) * sizeof(WCHAR) );
338 if (len < n) dst[len] = 0;
340 return len;
344 /*********************************************************************
345 * mbstowcs (NTDLL.@)
347 size_t __cdecl mbstowcs( WCHAR *dst, const char *src, size_t n )
349 DWORD len;
351 if (!dst)
353 RtlMultiByteToUnicodeSize( &len, src, strlen(src) );
355 else
357 if (n <= 0) return 0;
358 RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) );
359 if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0;
361 return len / sizeof(WCHAR);
365 /*********************************************************************
366 * iswctype (NTDLL.@)
368 INT __cdecl iswctype( WCHAR wc, unsigned short type )
370 if (wc >= 256) return 0;
371 return wctypes[wc] & type;
375 /*********************************************************************
376 * iswalpha (NTDLL.@)
378 INT __cdecl iswalpha( WCHAR wc )
380 if (wc >= 256) return 0;
381 return wctypes[wc] & (C1_ALPHA | C1_UPPER | C1_LOWER);
385 /*********************************************************************
386 * iswdigit (NTDLL.@)
388 * Checks if a unicode char wc is a digit
390 * RETURNS
391 * TRUE: The unicode char wc is a digit.
392 * FALSE: Otherwise
394 INT __cdecl iswdigit( WCHAR wc )
396 if (wc >= 256) return 0;
397 return wctypes[wc] & C1_DIGIT;
401 /*********************************************************************
402 * iswlower (NTDLL.@)
404 * Checks if a unicode char wc is a lower case letter
406 * RETURNS
407 * TRUE: The unicode char wc is a lower case letter.
408 * FALSE: Otherwise
410 INT __cdecl iswlower( WCHAR wc )
412 if (wc >= 256) return 0;
413 return wctypes[wc] & C1_LOWER;
417 /*********************************************************************
418 * iswspace (NTDLL.@)
420 * Checks if a unicode char wc is a white space character
422 * RETURNS
423 * TRUE: The unicode char wc is a white space character.
424 * FALSE: Otherwise
426 INT __cdecl iswspace( WCHAR wc )
428 if (wc >= 256) return 0;
429 return wctypes[wc] & C1_SPACE;
433 /*********************************************************************
434 * iswxdigit (NTDLL.@)
436 * Checks if a unicode char wc is an extended digit
438 * RETURNS
439 * TRUE: The unicode char wc is an extended digit.
440 * FALSE: Otherwise
442 INT __cdecl iswxdigit( WCHAR wc )
444 if (wc >= 256) return 0;
445 return wctypes[wc] & C1_XDIGIT;
449 static int wctoint( WCHAR c )
451 /* NOTE: MAP_FOLDDIGITS supports too many things. */
452 /* Unicode points that contain digits 0-9; keep this sorted! */
453 static const WCHAR zeros[] =
455 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0c66, 0x0ce6,
456 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0, 0x1810, 0xff10
458 int i;
460 if ('0' <= c && c <= '9') return c - '0';
461 if ('A' <= c && c <= 'Z') return c - 'A' + 10;
462 if ('a' <= c && c <= 'z') return c - 'a' + 10;
463 for (i = 0; i < ARRAY_SIZE(zeros) && c >= zeros[i]; i++)
464 if (zeros[i] <= c && c <= zeros[i] + 9) return c - zeros[i];
466 return -1;
469 /*********************************************************************
470 * wcstol (NTDLL.@)
472 __msvcrt_long __cdecl wcstol(LPCWSTR s, LPWSTR *end, INT base)
474 BOOL negative = FALSE, empty = TRUE;
475 LONG ret = 0;
477 if (base < 0 || base == 1 || base > 36) return 0;
478 if (end) *end = (WCHAR *)s;
479 while (iswspace(*s)) s++;
481 if (*s == '-')
483 negative = TRUE;
484 s++;
486 else if (*s == '+') s++;
488 if ((base == 0 || base == 16) && !wctoint( *s ) && (s[1] == 'x' || s[1] == 'X'))
490 base = 16;
491 s += 2;
493 if (base == 0) base = wctoint( *s ) ? 10 : 8;
495 while (*s)
497 int v = wctoint( *s );
498 if (v < 0 || v >= base) break;
499 if (negative) v = -v;
500 s++;
501 empty = FALSE;
503 if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
504 ret = MAXLONG;
505 else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
506 ret = MINLONG;
507 else
508 ret = ret * base + v;
511 if (end && !empty) *end = (WCHAR *)s;
512 return ret;
516 /*********************************************************************
517 * wcstoul (NTDLL.@)
519 __msvcrt_ulong __cdecl wcstoul(LPCWSTR s, LPWSTR *end, INT base)
521 BOOL negative = FALSE, empty = TRUE;
522 ULONG ret = 0;
524 if (base < 0 || base == 1 || base > 36) return 0;
525 if (end) *end = (WCHAR *)s;
526 while (iswspace(*s)) s++;
528 if (*s == '-')
530 negative = TRUE;
531 s++;
533 else if (*s == '+') s++;
535 if ((base == 0 || base == 16) && !wctoint( *s ) && (s[1] == 'x' || s[1] == 'X'))
537 base = 16;
538 s += 2;
540 if (base == 0) base = wctoint( *s ) ? 10 : 8;
542 while (*s)
544 int v = wctoint( *s );
545 if (v < 0 || v >= base) break;
546 s++;
547 empty = FALSE;
549 if (ret > MAXDWORD / base || ret * base > MAXDWORD - v)
550 ret = MAXDWORD;
551 else
552 ret = ret * base + v;
555 if (end && !empty) *end = (WCHAR *)s;
556 return negative ? -ret : ret;
560 /*********************************************************************
561 * _ultow (NTDLL.@)
563 * Converts an unsigned long integer to a unicode string.
565 * RETURNS
566 * Always returns str.
568 * NOTES
569 * Converts value to a '\0' terminated wstring which is copied to str.
570 * The maximum length of the copied str is 33 bytes.
571 * Does not check if radix is in the range of 2 to 36.
572 * If str is NULL it just returns NULL.
574 LPWSTR __cdecl _ultow( __msvcrt_ulong value, LPWSTR str, INT radix )
576 WCHAR buffer[33];
577 PWCHAR pos;
578 WCHAR digit;
580 pos = &buffer[32];
581 *pos = '\0';
583 do {
584 digit = value % radix;
585 value = value / radix;
586 if (digit < 10) {
587 *--pos = '0' + digit;
588 } else {
589 *--pos = 'a' + digit - 10;
590 } /* if */
591 } while (value != 0L);
593 if (str != NULL) {
594 memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
595 } /* if */
596 return str;
600 /*********************************************************************
601 * _ltow (NTDLL.@)
603 * Converts a long integer to a unicode string.
605 * RETURNS
606 * Always returns str.
608 * NOTES
609 * Converts value to a '\0' terminated wstring which is copied to str.
610 * The maximum length of the copied str is 33 bytes. If radix
611 * is 10 and value is negative, the value is converted with sign.
612 * Does not check if radix is in the range of 2 to 36.
613 * If str is NULL it just returns NULL.
615 LPWSTR __cdecl _ltow( __msvcrt_long value, LPWSTR str, INT radix )
617 ULONG val;
618 int negative;
619 WCHAR buffer[33];
620 PWCHAR pos;
621 WCHAR digit;
623 if (value < 0 && radix == 10) {
624 negative = 1;
625 val = -value;
626 } else {
627 negative = 0;
628 val = value;
629 } /* if */
631 pos = &buffer[32];
632 *pos = '\0';
634 do {
635 digit = val % radix;
636 val = val / radix;
637 if (digit < 10) {
638 *--pos = '0' + digit;
639 } else {
640 *--pos = 'a' + digit - 10;
641 } /* if */
642 } while (val != 0L);
644 if (negative) {
645 *--pos = '-';
646 } /* if */
648 if (str != NULL) {
649 memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
650 } /* if */
651 return str;
655 /*********************************************************************
656 * _itow (NTDLL.@)
658 * Converts an integer to a unicode string.
660 * RETURNS
661 * Always returns str.
663 * NOTES
664 * Converts value to a '\0' terminated wstring which is copied to str.
665 * The maximum length of the copied str is 33 bytes. If radix
666 * is 10 and value is negative, the value is converted with sign.
667 * Does not check if radix is in the range of 2 to 36.
668 * If str is NULL it just returns NULL.
670 * DIFFERENCES
671 * - The native function crashes when the string is longer than 19 chars.
672 * This function does not have this bug.
674 LPWSTR __cdecl _itow(
675 int value, /* [I] Value to be converted */
676 LPWSTR str, /* [O] Destination for the converted value */
677 INT radix) /* [I] Number base for conversion */
679 return _ltow(value, str, radix);
683 /*********************************************************************
684 * _ui64tow (NTDLL.@)
686 * Converts a large unsigned integer to a unicode string.
688 * RETURNS
689 * Always returns str.
691 * NOTES
692 * Converts value to a '\0' terminated wstring which is copied to str.
693 * The maximum length of the copied str is 33 bytes.
694 * Does not check if radix is in the range of 2 to 36.
695 * If str is NULL it just returns NULL.
697 * DIFFERENCES
698 * - This function does not exist in the native DLL (but in msvcrt).
699 * But since the maintenance of all these functions is better done
700 * in one place we implement it here.
702 LPWSTR __cdecl _ui64tow(
703 ULONGLONG value, /* [I] Value to be converted */
704 LPWSTR str, /* [O] Destination for the converted value */
705 INT radix) /* [I] Number base for conversion */
707 WCHAR buffer[65];
708 PWCHAR pos;
709 WCHAR digit;
711 pos = &buffer[64];
712 *pos = '\0';
714 do {
715 digit = value % radix;
716 value = value / radix;
717 if (digit < 10) {
718 *--pos = '0' + digit;
719 } else {
720 *--pos = 'a' + digit - 10;
721 } /* if */
722 } while (value != 0L);
724 if (str != NULL) {
725 memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
726 } /* if */
727 return str;
731 /*********************************************************************
732 * _i64tow (NTDLL.@)
734 * Converts a large integer to a unicode string.
736 * RETURNS
737 * Always returns str.
739 * NOTES
740 * Converts value to a '\0' terminated wstring which is copied to str.
741 * The maximum length of the copied str is 33 bytes. If radix
742 * is 10 and value is negative, the value is converted with sign.
743 * Does not check if radix is in the range of 2 to 36.
744 * If str is NULL it just returns NULL.
746 * DIFFERENCES
747 * - The native DLL converts negative values (for base 10) wrong:
748 * -1 is converted to -18446744073709551615
749 * -2 is converted to -18446744073709551614
750 * -9223372036854775807 is converted to -9223372036854775809
751 * -9223372036854775808 is converted to -9223372036854775808
752 * The native msvcrt _i64tow function and our ntdll function do
753 * not have this bug.
755 LPWSTR __cdecl _i64tow(
756 LONGLONG value, /* [I] Value to be converted */
757 LPWSTR str, /* [O] Destination for the converted value */
758 INT radix) /* [I] Number base for conversion */
760 ULONGLONG val;
761 int negative;
762 WCHAR buffer[65];
763 PWCHAR pos;
764 WCHAR digit;
766 if (value < 0 && radix == 10) {
767 negative = 1;
768 val = -value;
769 } else {
770 negative = 0;
771 val = value;
772 } /* if */
774 pos = &buffer[64];
775 *pos = '\0';
777 do {
778 digit = val % radix;
779 val = val / radix;
780 if (digit < 10) {
781 *--pos = '0' + digit;
782 } else {
783 *--pos = 'a' + digit - 10;
784 } /* if */
785 } while (val != 0L);
787 if (negative) {
788 *--pos = '-';
789 } /* if */
791 if (str != NULL) {
792 memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
793 } /* if */
794 return str;
798 /*********************************************************************
799 * _wtol (NTDLL.@)
801 * Converts a unicode string to a long integer.
803 * PARAMS
804 * str [I] Wstring to be converted
806 * RETURNS
807 * On success it returns the integer value otherwise it returns 0.
809 * NOTES
810 * Accepts: {whitespace} [+|-] {digits}
811 * No check is made for value overflow, only the lower 32 bits are assigned.
812 * If str is NULL it crashes, as the native function does.
814 __msvcrt_long __cdecl _wtol( LPCWSTR str )
816 ULONG RunningTotal = 0;
817 BOOL bMinus = FALSE;
819 while (iswspace(*str)) str++;
821 if (*str == '+') {
822 str++;
823 } else if (*str == '-') {
824 bMinus = TRUE;
825 str++;
826 } /* if */
828 while (*str >= '0' && *str <= '9') {
829 RunningTotal = RunningTotal * 10 + *str - '0';
830 str++;
831 } /* while */
833 return bMinus ? -RunningTotal : RunningTotal;
837 /*********************************************************************
838 * _wtoi (NTDLL.@)
840 * Converts a unicode string to an integer.
842 * PARAMS
843 * str [I] Wstring to be converted
845 * RETURNS
846 * On success it returns the integer value otherwise it returns 0.
848 * NOTES
849 * Accepts: {whitespace} [+|-] {digits}
850 * No check is made for value overflow, only the lower 32 bits are assigned.
851 * If str is NULL it crashes, as the native function does.
853 int __cdecl _wtoi( LPCWSTR str )
855 return _wtol(str);
859 /*********************************************************************
860 * _wtoi64 (NTDLL.@)
862 * Converts a unicode string to a large integer.
864 * PARAMS
865 * str [I] Wstring to be converted
867 * RETURNS
868 * On success it returns the integer value otherwise it returns 0.
870 * NOTES
871 * Accepts: {whitespace} [+|-] {digits}
872 * No check is made for value overflow, only the lower 64 bits are assigned.
873 * If str is NULL it crashes, as the native function does.
875 LONGLONG __cdecl _wtoi64( LPCWSTR str )
877 ULONGLONG RunningTotal = 0;
878 BOOL bMinus = FALSE;
880 while (iswspace(*str)) str++;
882 if (*str == '+') {
883 str++;
884 } else if (*str == '-') {
885 bMinus = TRUE;
886 str++;
887 } /* if */
889 while (*str >= '0' && *str <= '9') {
890 RunningTotal = RunningTotal * 10 + *str - '0';
891 str++;
892 } /* while */
894 return bMinus ? -RunningTotal : RunningTotal;