:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / string / strtoul.c
1 #include <crtdll/string.h>
2 #include <crtdll/ctype.h>
3
4 unsigned long strtoul(const char *cp,char **endp,unsigned int base)
5 {
6         unsigned long result = 0,value;
7
8         if (!base) {
9                 base = 10;
10                 if (*cp == '0') {
11                         base = 8;
12                         cp++;
13                         if ((*cp == 'x') && isxdigit(cp[1])) {
14                                 cp++;
15                                 base = 16;
16                         }
17                 }
18         }
19         while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
20             ? toupper(*cp) : *cp)-'A'+10) < base) {
21                 result = result*base + value;
22                 cp++;
23         }
24         if (endp)
25                 *endp = (char *)cp;
26         return result;
27 }