update for HEAD-2003021201
[reactos.git] / lib / crtdll / wchar / wcstol.c
1 #include <msvcrt/wchar.h>
2
3
4 long wcstol(const wchar_t* cp, wchar_t** endp, int base)
5 {
6         long result = 0, value;
7         int sign = 1;
8
9         if (*cp == L'-') {
10                 sign = -1;
11                 cp++;
12         }
13
14         if (!base) {
15                 base = 10;
16                 if (*cp == L'0') {
17                         base = 8;
18                         cp++;
19                         if ((*cp == L'x') && iswxdigit(cp[1])) {
20                                 cp++;
21                                 base = 16;
22                         }
23                 }
24         }
25         while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp)
26             ? towupper(*cp) : *cp)-L'A'+10) < base) {
27                 result = result*base + value;
28                 cp++;
29         }
30         if (endp)
31                 *endp = (wchar_t*)cp;
32         return result * sign;
33 }
34
35 unsigned long wcstoul(const wchar_t* cp, wchar_t** endp, int base)
36 {
37         unsigned long result = 0, value;
38
39         if (!base) {
40                 base = 10;
41                 if (*cp == L'0') {
42                         base = 8;
43                         cp++;
44                         if ((*cp == L'x') && iswxdigit(cp[1])) {
45                                 cp++;
46                                 base = 16;
47                         }
48                 }
49         }
50         while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp)
51             ? towupper(*cp) : *cp)-L'A'+10) < base) {
52                 result = result*base + value;
53                 cp++;
54         }
55         if (endp)
56                 *endp = (wchar_t*)cp;
57         return result;
58 }