1 /* 2 * Copyright (C) 1991, 1992 Linus Torvalds 3 */ 4 5 #include <xen/ctype.h> 6 #include <xen/lib.h> 7 8 /** 9 * simple_strtoull - convert a string to an unsigned long long 10 * @cp: The start of the string 11 * @endp: A pointer to the end of the parsed string will be placed here 12 * @base: The number base to use 13 */ simple_strtoull(const char * cp,const char ** endp,unsigned int base)14unsigned long long simple_strtoull( 15 const char *cp, const char **endp, unsigned int base) 16 { 17 unsigned long long result = 0, value; 18 19 if ( !base ) 20 { 21 base = 10; 22 if ( *cp == '0' ) 23 { 24 base = 8; 25 cp++; 26 if ( (toupper(*cp) == 'X') && isxdigit(cp[1]) ) 27 { 28 cp++; 29 base = 16; 30 } 31 } 32 } 33 else if ( base == 16 ) 34 { 35 if ( cp[0] == '0' && toupper(cp[1]) == 'X' ) 36 cp += 2; 37 } 38 39 while ( isxdigit(*cp) && 40 (value = isdigit(*cp) ? *cp - '0' 41 : (islower(*cp) ? toupper(*cp) 42 : *cp) - 'A' + 10) < base ) 43 { 44 result = result * base + value; 45 cp++; 46 } 47 48 if ( endp ) 49 *endp = cp; 50 51 return result; 52 } 53 54 /* 55 * Local variables: 56 * mode: C 57 * c-file-style: "BSD" 58 * c-basic-offset: 4 59 * tab-width: 4 60 * indent-tabs-mode: nil 61 * End: 62 */ 63