[crt]
[reactos.git] / reactos / lib / sdk / crt / string / wtol.c
1 #include <string.h>
2 #include <ctype.h>
3 #include <basetsd.h>
4
5 /* Implementation comes from wine/dlls/ntdll/wcstring.c */
6
7 /*
8 * @implemented
9 */
10 long
11 _wtol(const wchar_t *str)
12 {
13 unsigned long RunningTotal = 0;
14 char bMinus = 0;
15
16 if (str == NULL)
17 return 0;
18
19 while (iswctype(*str, _SPACE) ) {
20 str++;
21 } /* while */
22
23 if (*str == L'+') {
24 str++;
25 } else if (*str == L'-') {
26 bMinus = 1;
27 str++;
28 } /* if */
29
30 while (*str >= L'0' && *str <= L'9') {
31 RunningTotal = RunningTotal * 10 + *str - L'0';
32 str++;
33 } /* while */
34
35 return bMinus ? 0-RunningTotal : RunningTotal;
36 }
37
38