Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstrtoi64.c
Go to the documentation of this file.
00001 #include <precomp.h> 00002 00003 00004 __int64 00005 _strtoi64(const char *nptr, char **endptr, int base) 00006 { 00007 BOOL negative = FALSE; 00008 __int64 ret = 0; 00009 00010 while(isspace(*nptr)) nptr++; 00011 00012 if(*nptr == '-') { 00013 negative = TRUE; 00014 nptr++; 00015 } else if(*nptr == '+') 00016 nptr++; 00017 00018 if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') { 00019 base = 16; 00020 nptr += 2; 00021 } 00022 00023 if(base == 0) { 00024 if(*nptr=='0') 00025 base = 8; 00026 else 00027 base = 10; 00028 } 00029 00030 while(*nptr) { 00031 char cur = tolower(*nptr); 00032 int v; 00033 00034 if(isdigit(cur)) { 00035 if(cur >= '0'+base) 00036 break; 00037 v = cur-'0'; 00038 } else { 00039 if(cur<'a' || cur>='a'+base-10) 00040 break; 00041 v = cur-'a'+10; 00042 } 00043 00044 if(negative) 00045 v = -v; 00046 00047 nptr++; 00048 00049 if(!negative && (ret>_I64_MAX/base || ret*base>_I64_MAX-v)) { 00050 ret = _I64_MAX; 00051 *_errno() = ERANGE; 00052 } else if(negative && (ret<_I64_MIN/base || ret*base<_I64_MIN-v)) { 00053 ret = _I64_MIN; 00054 *_errno() = ERANGE; 00055 } else 00056 ret = ret*base + v; 00057 } 00058 00059 if(endptr) 00060 *endptr = (char*)nptr; 00061 00062 return ret; 00063 } 00064 00065 00066 /* EOF */ Generated on Fri May 25 2012 04:35:10 for ReactOS by
1.7.6.1
|