diff options
author | 2015-08-28 09:58:54 +0800 | |
---|---|---|
committer | 2015-09-01 12:44:00 +0800 | |
commit | e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch) | |
tree | 66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/ipxe/src/core/misc.c | |
parent | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff) |
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/ipxe/src/core/misc.c')
-rw-r--r-- | qemu/roms/ipxe/src/core/misc.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/qemu/roms/ipxe/src/core/misc.c b/qemu/roms/ipxe/src/core/misc.c new file mode 100644 index 000000000..eaceddfea --- /dev/null +++ b/qemu/roms/ipxe/src/core/misc.c @@ -0,0 +1,85 @@ +/************************************************************************** +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> + +/************************************************************************** +INET_ATON - Convert an ascii x.x.x.x to binary form +**************************************************************************/ +int inet_aton ( const char *cp, struct in_addr *inp ) { + const char *p = cp; + const char *digits_start; + unsigned long ip = 0; + unsigned long val; + int j; + for(j = 0; j <= 3; j++) { + digits_start = p; + val = strtoul(p, ( char ** ) &p, 10); + if ((p == digits_start) || (val > 255)) return 0; + if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0; + ip = (ip << 8) | val; + } + if ( *p == '\0' ) { + inp->s_addr = htonl(ip); + return 1; + } + return 0; +} + +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 ) { + 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 ); + p++; + } + + if ( negative ) + ret = -ret; + + if ( endp ) + *endp = ( char * ) p; + + return ( ret ); +} + +/* + * Local variables: + * c-basic-offset: 8 + * End: + */ |