Added netdev_nullify to natsemi_remove()
[gpxe.git] / src / core / misc.c
blob4219a36c557d3d506a40204b6b98a5773294112a
1 /**************************************************************************
2 MISC Support Routines
3 **************************************************************************/
5 #include <stdlib.h>
6 #include <byteswap.h>
7 #include <latch.h>
8 #include <gpxe/in.h>
10 /**************************************************************************
11 SLEEP
12 **************************************************************************/
13 unsigned int sleep(unsigned int secs)
15 unsigned long tmo;
17 for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; ) {
19 return 0;
22 /**************************************************************************
23 INET_ATON - Convert an ascii x.x.x.x to binary form
24 **************************************************************************/
25 int inet_aton ( const char *cp, struct in_addr *inp ) {
26 const char *p = cp;
27 const char *digits_start;
28 unsigned long ip = 0;
29 unsigned long val;
30 int j;
31 for(j = 0; j <= 3; j++) {
32 digits_start = p;
33 val = strtoul(p, ( char ** ) &p, 10);
34 if ((p == digits_start) || (val > 255)) return 0;
35 if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
36 ip = (ip << 8) | val;
38 if ( *p == '\0' ) {
39 inp->s_addr = htonl(ip);
40 return 1;
42 return 0;
45 int isspace ( int c ) {
46 switch ( c ) {
47 case ' ':
48 case '\f':
49 case '\n':
50 case '\r':
51 case '\t':
52 case '\v':
53 return 1;
54 default:
55 return 0;
59 unsigned long strtoul ( const char *p, char **endp, int base ) {
60 unsigned long ret = 0;
61 unsigned int charval;
63 while ( isspace ( *p ) )
64 p++;
66 if ( base == 0 ) {
67 base = 10;
68 if ( *p == '0' ) {
69 p++;
70 base = 8;
71 if ( ( *p | 0x20 ) == 'x' ) {
72 p++;
73 base = 16;
78 while ( 1 ) {
79 charval = *p;
80 if ( charval >= 'a' ) {
81 charval = ( charval - 'a' + 10 );
82 } else if ( charval >= 'A' ) {
83 charval = ( charval - 'A' + 10 );
84 } else {
85 charval = ( charval - '0' );
87 if ( charval >= ( unsigned int ) base )
88 break;
89 ret = ( ( ret * base ) + charval );
90 p++;
93 if ( endp )
94 *endp = ( char * ) p;
96 return ( ret );
100 * Local variables:
101 * c-basic-offset: 8
102 * End: