summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2006-11-15 03:52:06 +0100
committerMichael Brown2006-11-15 03:52:06 +0100
commit65ff5357f12fddcbba492e062500564b76b34b40 (patch)
tree8fc5ba169e0fb9a8215fe83fcc719cc96fa9a68a /src/core
parentSplit login into security negotation and operational parameter (diff)
downloadipxe-65ff5357f12fddcbba492e062500564b76b34b40.tar.gz
ipxe-65ff5357f12fddcbba492e062500564b76b34b40.tar.xz
ipxe-65ff5357f12fddcbba492e062500564b76b34b40.zip
Extend strtoul() to cope with hex as well as decimal. Doesn't cope
with octal yet, but we can probably live without that.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/misc.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/core/misc.c b/src/core/misc.c
index 77b22659d..2765f7dcc 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -150,18 +150,34 @@ int inet_aton ( const char *cp, struct in_addr *inp ) {
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;
- if (base != 10) return 0;
- while((*p >= '0') && (*p <= '9')) {
- ret = ret*10 + (*p - '0');
- p++;
+ unsigned int charval;
+
+ if ( base == 0 ) {
+ if ( ( p[0] == '0' ) && ( ( p[1] | 0x20 ) == 'x' ) ) {
+ base = 16;
+ p += 2;
+ } else {
+ base = 10;
+ }
+ }
+
+ 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)
+
+ if ( endp )
*endp = ( char * ) p;
- return(ret);
-
+
+ return ( ret );
}
/*