winebus.sys: Add missing keyboard free_device callback.
[wine.git] / dlls / ntdll / wcstring.c
bloba727e4defac10a7dca15ca4756091a9b71d857bc
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 #undef wcsncpy
245 LPWSTR __cdecl wcsncpy( LPWSTR s1, LPCWSTR s2, size_t n )
247 WCHAR *ret = s1;
248 for ( ; n; n--) if (!(*s1++ = *s2++)) break;
249 for ( ; n; n--) *s1++ = 0;
250 return ret;
254 /*********************************************************************
255 * wcspbrk (NTDLL.@)
257 LPWSTR __cdecl wcspbrk( LPCWSTR str, LPCWSTR accept )
259 for ( ; *str; str++) if (wcschr( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
260 return NULL;
264 /*********************************************************************
265 * wcsrchr (NTDLL.@)
267 LPWSTR __cdecl wcsrchr( LPCWSTR str, WCHAR ch )
269 WCHAR *ret = NULL;
270 do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
271 return ret;
275 /*********************************************************************
276 * wcsspn (NTDLL.@)
278 size_t __cdecl wcsspn( LPCWSTR str, LPCWSTR accept )
280 const WCHAR *ptr;
281 for (ptr = str; *ptr; ptr++) if (!wcschr( accept, *ptr )) break;
282 return ptr - str;
286 /*********************************************************************
287 * wcsstr (NTDLL.@)
289 LPWSTR __cdecl wcsstr( LPCWSTR str, LPCWSTR sub )
291 while (*str)
293 const WCHAR *p1 = str, *p2 = sub;
294 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
295 if (!*p2) return (WCHAR *)str;
296 str++;
298 return NULL;
302 /*********************************************************************
303 * wcstok (NTDLL.@)
305 LPWSTR __cdecl wcstok( LPWSTR str, LPCWSTR delim )
307 static LPWSTR next = NULL;
308 LPWSTR ret;
310 if (!str)
311 if (!(str = next)) return NULL;
313 while (*str && wcschr( delim, *str )) str++;
314 if (!*str) return NULL;
315 ret = str++;
316 while (*str && !wcschr( delim, *str )) str++;
317 if (*str) *str++ = 0;
318 next = str;
319 return ret;
323 /*********************************************************************
324 * wcstombs (NTDLL.@)
326 size_t __cdecl wcstombs( char *dst, const WCHAR *src, size_t n )
328 DWORD len;
330 if (!dst)
332 RtlUnicodeToMultiByteSize( &len, src, wcslen(src) * sizeof(WCHAR) );
333 return len;
335 else
337 if (n <= 0) return 0;
338 RtlUnicodeToMultiByteN( dst, n, &len, src, wcslen(src) * sizeof(WCHAR) );
339 if (len < n) dst[len] = 0;
341 return len;
345 /*********************************************************************
346 * mbstowcs (NTDLL.@)
348 size_t __cdecl mbstowcs( WCHAR *dst, const char *src, size_t n )
350 DWORD len;
352 if (!dst)
354 RtlMultiByteToUnicodeSize( &len, src, strlen(src) );
356 else
358 if (n <= 0) return 0;
359 RtlMultiByteToUnicodeN( dst, n*sizeof(WCHAR), &len, src, strlen(src) );
360 if (len / sizeof(WCHAR) < n) dst[len / sizeof(WCHAR)] = 0;
362 return len / sizeof(WCHAR);
366 /*********************************************************************
367 * iswctype (NTDLL.@)
369 INT __cdecl iswctype( WCHAR wc, unsigned short type )
371 if (wc >= 256) return 0;
372 return wctypes[wc] & type;
376 /*********************************************************************
377 * iswalpha (NTDLL.@)
379 INT __cdecl iswalpha( WCHAR wc )
381 if (wc >= 256) return 0;
382 return wctypes[wc] & (C1_ALPHA | C1_UPPER | C1_LOWER);
386 /*********************************************************************
387 * iswdigit (NTDLL.@)
389 * Checks if a unicode char wc is a digit
391 * RETURNS
392 * TRUE: The unicode char wc is a digit.
393 * FALSE: Otherwise
395 INT __cdecl iswdigit( WCHAR wc )
397 if (wc >= 256) return 0;
398 return wctypes[wc] & C1_DIGIT;
402 /*********************************************************************
403 * iswlower (NTDLL.@)
405 * Checks if a unicode char wc is a lower case letter
407 * RETURNS
408 * TRUE: The unicode char wc is a lower case letter.
409 * FALSE: Otherwise
411 INT __cdecl iswlower( WCHAR wc )
413 if (wc >= 256) return 0;
414 return wctypes[wc] & C1_LOWER;
418 /*********************************************************************
419 * iswspace (NTDLL.@)
421 * Checks if a unicode char wc is a white space character
423 * RETURNS
424 * TRUE: The unicode char wc is a white space character.
425 * FALSE: Otherwise
427 INT __cdecl iswspace( WCHAR wc )
429 if (wc >= 256) return 0;
430 return wctypes[wc] & C1_SPACE;
434 /*********************************************************************
435 * iswxdigit (NTDLL.@)
437 * Checks if a unicode char wc is an extended digit
439 * RETURNS
440 * TRUE: The unicode char wc is an extended digit.
441 * FALSE: Otherwise
443 INT __cdecl iswxdigit( WCHAR wc )
445 if (wc >= 256) return 0;
446 return wctypes[wc] & C1_XDIGIT;
450 static int wctoint( WCHAR c )
452 /* NOTE: MAP_FOLDDIGITS supports too many things. */
453 /* Unicode points that contain digits 0-9; keep this sorted! */
454 static const WCHAR zeros[] =
456 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0c66, 0x0ce6,
457 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0, 0x1810, 0xff10
459 int i;
461 if ('0' <= c && c <= '9') return c - '0';
462 if ('A' <= c && c <= 'Z') return c - 'A' + 10;
463 if ('a' <= c && c <= 'z') return c - 'a' + 10;
464 for (i = 0; i < ARRAY_SIZE(zeros) && c >= zeros[i]; i++)
465 if (zeros[i] <= c && c <= zeros[i] + 9) return c - zeros[i];
467 return -1;
470 /*********************************************************************
471 * wcstol (NTDLL.@)
473 __msvcrt_long __cdecl wcstol(LPCWSTR s, LPWSTR *end, INT base)
475 BOOL negative = FALSE, empty = TRUE;
476 LONG ret = 0;
478 if (base < 0 || base == 1 || base > 36) return 0;
479 if (end) *end = (WCHAR *)s;
480 while (iswspace(*s)) s++;
482 if (*s == '-')
484 negative = TRUE;
485 s++;
487 else if (*s == '+') s++;
489 if ((base == 0 || base == 16) && !wctoint( *s ) && (s[1] == 'x' || s[1] == 'X'))
491 base = 16;
492 s += 2;
494 if (base == 0) base = wctoint( *s ) ? 10 : 8;
496 while (*s)
498 int v = wctoint( *s );
499 if (v < 0 || v >= base) break;
500 if (negative) v = -v;
501 s++;
502 empty = FALSE;
504 if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
505 ret = MAXLONG;
506 else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
507 ret = MINLONG;
508 else
509 ret = ret * base + v;
512 if (end && !empty) *end = (WCHAR *)s;
513 return ret;
517 /*********************************************************************
518 * wcstoul (NTDLL.@)
520 __msvcrt_ulong __cdecl wcstoul(LPCWSTR s, LPWSTR *end, INT base)
522 BOOL negative = FALSE, empty = TRUE;
523 ULONG ret = 0;
525 if (base < 0 || base == 1 || base > 36) return 0;
526 if (end) *end = (WCHAR *)s;
527 while (iswspace(*s)) s++;
529 if (*s == '-')
531 negative = TRUE;
532 s++;
534 else if (*s == '+') s++;
536 if ((base == 0 || base == 16) && !wctoint( *s ) && (s[1] == 'x' || s[1] == 'X'))
538 base = 16;
539 s += 2;
541 if (base == 0) base = wctoint( *s ) ? 10 : 8;
543 while (*s)
545 int v = wctoint( *s );
546 if (v < 0 || v >= base) break;
547 s++;
548 empty = FALSE;
550 if (ret > MAXDWORD / base || ret * base > MAXDWORD - v)
551 ret = MAXDWORD;
552 else
553 ret = ret * base + v;
556 if (end && !empty) *end = (WCHAR *)s;
557 return negative ? -ret : ret;
561 /*********************************************************************
562 * _ultow (NTDLL.@)
564 * Converts an unsigned long integer to a unicode string.
566 * RETURNS
567 * Always returns str.
569 * NOTES
570 * Converts value to a '\0' terminated wstring which is copied to str.
571 * The maximum length of the copied str is 33 bytes.
572 * Does not check if radix is in the range of 2 to 36.
573 * If str is NULL it just returns NULL.
575 LPWSTR __cdecl _ultow( __msvcrt_ulong value, LPWSTR str, INT radix )
577 WCHAR buffer[33];
578 PWCHAR pos;
579 WCHAR digit;
581 pos = &buffer[32];
582 *pos = '\0';
584 do {
585 digit = value % radix;
586 value = value / radix;
587 if (digit < 10) {
588 *--pos = '0' + digit;
589 } else {
590 *--pos = 'a' + digit - 10;
591 } /* if */
592 } while (value != 0L);
594 if (str != NULL) {
595 memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
596 } /* if */
597 return str;
601 /*********************************************************************
602 * _ltow (NTDLL.@)
604 * Converts a long integer to a unicode string.
606 * RETURNS
607 * Always returns str.
609 * NOTES
610 * Converts value to a '\0' terminated wstring which is copied to str.
611 * The maximum length of the copied str is 33 bytes. If radix
612 * is 10 and value is negative, the value is converted with sign.
613 * Does not check if radix is in the range of 2 to 36.
614 * If str is NULL it just returns NULL.
616 LPWSTR __cdecl _ltow( __msvcrt_long value, LPWSTR str, INT radix )
618 ULONG val;
619 int negative;
620 WCHAR buffer[33];
621 PWCHAR pos;
622 WCHAR digit;
624 if (value < 0 && radix == 10) {
625 negative = 1;
626 val = -value;
627 } else {
628 negative = 0;
629 val = value;
630 } /* if */
632 pos = &buffer[32];
633 *pos = '\0';
635 do {
636 digit = val % radix;
637 val = val / radix;
638 if (digit < 10) {
639 *--pos = '0' + digit;
640 } else {
641 *--pos = 'a' + digit - 10;
642 } /* if */
643 } while (val != 0L);
645 if (negative) {
646 *--pos = '-';
647 } /* if */
649 if (str != NULL) {
650 memcpy(str, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
651 } /* if */
652 return str;
656 /*********************************************************************
657 * _itow (NTDLL.@)
659 * Converts an integer to a unicode string.
661 * RETURNS
662 * Always returns str.
664 * NOTES
665 * Converts value to a '\0' terminated wstring which is copied to str.
666 * The maximum length of the copied str is 33 bytes. If radix
667 * is 10 and value is negative, the value is converted with sign.
668 * Does not check if radix is in the range of 2 to 36.
669 * If str is NULL it just returns NULL.
671 * DIFFERENCES
672 * - The native function crashes when the string is longer than 19 chars.
673 * This function does not have this bug.
675 LPWSTR __cdecl _itow(
676 int value, /* [I] Value to be converted */
677 LPWSTR str, /* [O] Destination for the converted value */
678 INT radix) /* [I] Number base for conversion */
680 return _ltow(value, str, radix);
684 /*********************************************************************
685 * _ui64tow (NTDLL.@)
687 * Converts a large unsigned integer to a unicode string.
689 * RETURNS
690 * Always returns str.
692 * NOTES
693 * Converts value to a '\0' terminated wstring which is copied to str.
694 * The maximum length of the copied str is 33 bytes.
695 * Does not check if radix is in the range of 2 to 36.
696 * If str is NULL it just returns NULL.
698 * DIFFERENCES
699 * - This function does not exist in the native DLL (but in msvcrt).
700 * But since the maintenance of all these functions is better done
701 * in one place we implement it here.
703 LPWSTR __cdecl _ui64tow(
704 ULONGLONG value, /* [I] Value to be converted */
705 LPWSTR str, /* [O] Destination for the converted value */
706 INT radix) /* [I] Number base for conversion */
708 WCHAR buffer[65];
709 PWCHAR pos;
710 WCHAR digit;
712 pos = &buffer[64];
713 *pos = '\0';
715 do {
716 digit = value % radix;
717 value = value / radix;
718 if (digit < 10) {
719 *--pos = '0' + digit;
720 } else {
721 *--pos = 'a' + digit - 10;
722 } /* if */
723 } while (value != 0L);
725 if (str != NULL) {
726 memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
727 } /* if */
728 return str;
732 /*********************************************************************
733 * _i64tow (NTDLL.@)
735 * Converts a large integer to a unicode string.
737 * RETURNS
738 * Always returns str.
740 * NOTES
741 * Converts value to a '\0' terminated wstring which is copied to str.
742 * The maximum length of the copied str is 33 bytes. If radix
743 * is 10 and value is negative, the value is converted with sign.
744 * Does not check if radix is in the range of 2 to 36.
745 * If str is NULL it just returns NULL.
747 * DIFFERENCES
748 * - The native DLL converts negative values (for base 10) wrong:
749 * -1 is converted to -18446744073709551615
750 * -2 is converted to -18446744073709551614
751 * -9223372036854775807 is converted to -9223372036854775809
752 * -9223372036854775808 is converted to -9223372036854775808
753 * The native msvcrt _i64tow function and our ntdll function do
754 * not have this bug.
756 LPWSTR __cdecl _i64tow(
757 LONGLONG value, /* [I] Value to be converted */
758 LPWSTR str, /* [O] Destination for the converted value */
759 INT radix) /* [I] Number base for conversion */
761 ULONGLONG val;
762 int negative;
763 WCHAR buffer[65];
764 PWCHAR pos;
765 WCHAR digit;
767 if (value < 0 && radix == 10) {
768 negative = 1;
769 val = -value;
770 } else {
771 negative = 0;
772 val = value;
773 } /* if */
775 pos = &buffer[64];
776 *pos = '\0';
778 do {
779 digit = val % radix;
780 val = val / radix;
781 if (digit < 10) {
782 *--pos = '0' + digit;
783 } else {
784 *--pos = 'a' + digit - 10;
785 } /* if */
786 } while (val != 0L);
788 if (negative) {
789 *--pos = '-';
790 } /* if */
792 if (str != NULL) {
793 memcpy(str, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
794 } /* if */
795 return str;
799 /*********************************************************************
800 * _wtol (NTDLL.@)
802 * Converts a unicode string to a long integer.
804 * PARAMS
805 * str [I] Wstring to be converted
807 * RETURNS
808 * On success it returns the integer value otherwise it returns 0.
810 * NOTES
811 * Accepts: {whitespace} [+|-] {digits}
812 * No check is made for value overflow, only the lower 32 bits are assigned.
813 * If str is NULL it crashes, as the native function does.
815 __msvcrt_long __cdecl _wtol( LPCWSTR str )
817 ULONG RunningTotal = 0;
818 BOOL bMinus = FALSE;
820 while (iswspace(*str)) str++;
822 if (*str == '+') {
823 str++;
824 } else if (*str == '-') {
825 bMinus = TRUE;
826 str++;
827 } /* if */
829 while (*str >= '0' && *str <= '9') {
830 RunningTotal = RunningTotal * 10 + *str - '0';
831 str++;
832 } /* while */
834 return bMinus ? -RunningTotal : RunningTotal;
838 /*********************************************************************
839 * _wtoi (NTDLL.@)
841 * Converts a unicode string to an integer.
843 * PARAMS
844 * str [I] Wstring to be converted
846 * RETURNS
847 * On success it returns the integer value otherwise it returns 0.
849 * NOTES
850 * Accepts: {whitespace} [+|-] {digits}
851 * No check is made for value overflow, only the lower 32 bits are assigned.
852 * If str is NULL it crashes, as the native function does.
854 int __cdecl _wtoi( LPCWSTR str )
856 return _wtol(str);
860 /*********************************************************************
861 * _wtoi64 (NTDLL.@)
863 * Converts a unicode string to a large integer.
865 * PARAMS
866 * str [I] Wstring to be converted
868 * RETURNS
869 * On success it returns the integer value otherwise it returns 0.
871 * NOTES
872 * Accepts: {whitespace} [+|-] {digits}
873 * No check is made for value overflow, only the lower 64 bits are assigned.
874 * If str is NULL it crashes, as the native function does.
876 LONGLONG __cdecl _wtoi64( LPCWSTR str )
878 ULONGLONG RunningTotal = 0;
879 BOOL bMinus = FALSE;
881 while (iswspace(*str)) str++;
883 if (*str == '+') {
884 str++;
885 } else if (*str == '-') {
886 bMinus = TRUE;
887 str++;
888 } /* if */
890 while (*str >= '0' && *str <= '9') {
891 RunningTotal = RunningTotal * 10 + *str - '0';
892 str++;
893 } /* while */
895 return bMinus ? -RunningTotal : RunningTotal;