david/ipxe
david
/
ipxe
Archived
1
0
Fork 0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
ipxe/src/core/misc.c

63 lines
1.1 KiB
C
Raw Normal View History

2005-03-08 19:53:11 +01:00
/**************************************************************************
MISC Support Routines
**************************************************************************/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdlib.h>
#include <ctype.h>
#include <byteswap.h>
#include <ipxe/in.h>
#include <ipxe/timer.h>
2005-03-08 19:53:11 +01:00
unsigned int strtoul_charval ( unsigned int charval ) {
if ( charval >= 'a' ) {
charval = ( charval - 'a' + 10 );
} else if ( charval >= 'A' ) {
charval = ( charval - 'A' + 10 );
} else if ( charval <= '9' ) {
charval = ( charval - '0' );
}
return charval;
}
unsigned long strtoul ( const char *p, char **endp, int base ) {
2005-03-08 19:53:11 +01:00
unsigned long ret = 0;
int negative = 0;
unsigned int charval;
while ( isspace ( *p ) )
p++;
if ( *p == '-' ) {
negative = 1;
p++;
}
base = strtoul_base ( &p, base );
while ( 1 ) {
charval = strtoul_charval ( *p );
if ( charval >= ( unsigned int ) base )
break;
ret = ( ( ret * base ) + charval );
2006-11-15 03:54:28 +01:00
p++;
2005-03-08 19:53:11 +01:00
}
if ( negative )
ret = -ret;
if ( endp )
*endp = ( char * ) p;
return ( ret );
2005-03-08 19:53:11 +01:00
}
/*
* Local variables:
* c-basic-offset: 8
* End:
*/