mirror of https://github.com/ipxe/ipxe.git
Extend strtoul() to cope with hex as well as decimal. Doesn't cope
with octal yet, but we can probably live without that.pull/1/head
parent
fedc186fd7
commit
65ff5357f1
|
@ -150,18 +150,34 @@ int inet_aton ( const char *cp, struct in_addr *inp ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long strtoul(const char *p, char **endp, int base)
|
unsigned long strtoul ( const char *p, char **endp, int base ) {
|
||||||
{
|
|
||||||
unsigned long ret = 0;
|
unsigned long ret = 0;
|
||||||
if (base != 10) return 0;
|
unsigned int charval;
|
||||||
while((*p >= '0') && (*p <= '9')) {
|
|
||||||
ret = ret*10 + (*p - '0');
|
if ( base == 0 ) {
|
||||||
p++;
|
if ( ( p[0] == '0' ) && ( ( p[1] | 0x20 ) == 'x' ) ) {
|
||||||
|
base = 16;
|
||||||
|
p += 2;
|
||||||
|
} else {
|
||||||
|
base = 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (endp)
|
|
||||||
|
while ( 1 ) {
|
||||||
|
charval = *(p++) - '0';
|
||||||
|
if ( charval > ( 'A' - '0' - 10 ) )
|
||||||
|
charval -= ( 'A' - '0' - 10 );
|
||||||
|
if ( charval > ( 'a' - 'A' ) )
|
||||||
|
charval -= ( 'a' - 'A' );
|
||||||
|
if ( charval >= ( unsigned int ) base )
|
||||||
|
break;
|
||||||
|
ret = ( ( ret * base ) + charval );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( endp )
|
||||||
*endp = ( char * ) p;
|
*endp = ( char * ) p;
|
||||||
return(ret);
|
|
||||||
|
return ( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue