Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstrtoull.c
Go to the documentation of this file.
00001 #include <precomp.h> 00002 00003 unsigned long long 00004 strtoull(const char *nptr, char **endptr, int base) 00005 { 00006 const char *s = nptr; 00007 unsigned long long acc; 00008 int c; 00009 unsigned long long cutoff; 00010 int neg = 0, any, cutlim; 00011 00012 /* 00013 * See strtol for comments as to the logic used. 00014 */ 00015 do { 00016 c = *s++; 00017 } while (isspace(c)); 00018 if (c == '-') 00019 { 00020 neg = 1; 00021 c = *s++; 00022 } 00023 else if (c == '+') 00024 c = *s++; 00025 if ((base == 0 || base == 16) && 00026 c == '0' && (*s == 'x' || *s == 'X')) 00027 { 00028 c = s[1]; 00029 s += 2; 00030 base = 16; 00031 } 00032 if (base == 0) 00033 base = c == '0' ? 8 : 10; 00034 cutoff = (unsigned long long)ULLONG_MAX / (unsigned long long)base; 00035 cutlim = (unsigned long long)ULLONG_MAX % (unsigned long long)base; 00036 for (acc = 0, any = 0;; c = *s++) 00037 { 00038 if (isdigit(c)) 00039 c -= '0'; 00040 else if (isalpha(c)) 00041 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 00042 else 00043 break; 00044 if (c >= base) 00045 break; 00046 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 00047 any = -1; 00048 else { 00049 any = 1; 00050 acc *= base; 00051 acc += c; 00052 } 00053 } 00054 if (any < 0) 00055 { 00056 acc = ULLONG_MAX; 00057 #ifndef _LIBCNT_ 00058 _set_errno(ERANGE); 00059 #endif 00060 } 00061 else if (neg) 00062 acc = 0-acc; 00063 if (endptr != 0) 00064 *endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr); 00065 return acc; 00066 } Generated on Sun May 27 2012 04:36:46 for ReactOS by
1.7.6.1
|