[sundance] Add reset completion check
[gpxe.git] / src / core / misc.c
blob1f51272dc7490a78083ecb5dc35e5ae66b5a2222
1 /**************************************************************************
2 MISC Support Routines
3 **************************************************************************/
5 #include <stdlib.h>
6 #include <byteswap.h>
7 #include <gpxe/in.h>
8 #include <gpxe/timer.h>
10 /**************************************************************************
11 INET_ATON - Convert an ascii x.x.x.x to binary form
12 **************************************************************************/
13 int inet_aton ( const char *cp, struct in_addr *inp ) {
14 const char *p = cp;
15 const char *digits_start;
16 unsigned long ip = 0;
17 unsigned long val;
18 int j;
19 for(j = 0; j <= 3; j++) {
20 digits_start = p;
21 val = strtoul(p, ( char ** ) &p, 10);
22 if ((p == digits_start) || (val > 255)) return 0;
23 if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
24 ip = (ip << 8) | val;
26 if ( *p == '\0' ) {
27 inp->s_addr = htonl(ip);
28 return 1;
30 return 0;
33 int isspace ( int c ) {
34 switch ( c ) {
35 case ' ':
36 case '\f':
37 case '\n':
38 case '\r':
39 case '\t':
40 case '\v':
41 return 1;
42 default:
43 return 0;
47 unsigned long strtoul ( const char *p, char **endp, int base ) {
48 unsigned long ret = 0;
49 unsigned int charval;
51 while ( isspace ( *p ) )
52 p++;
54 if ( base == 0 ) {
55 base = 10;
56 if ( *p == '0' ) {
57 p++;
58 base = 8;
59 if ( ( *p | 0x20 ) == 'x' ) {
60 p++;
61 base = 16;
66 while ( 1 ) {
67 charval = *p;
68 if ( charval >= 'a' ) {
69 charval = ( charval - 'a' + 10 );
70 } else if ( charval >= 'A' ) {
71 charval = ( charval - 'A' + 10 );
72 } else if ( charval <= '9' ) {
73 charval = ( charval - '0' );
75 if ( charval >= ( unsigned int ) base )
76 break;
77 ret = ( ( ret * base ) + charval );
78 p++;
81 if ( endp )
82 *endp = ( char * ) p;
84 return ( ret );
88 * Local variables:
89 * c-basic-offset: 8
90 * End: