int islower( int c ) { return __islower(c); }
unsigned long inet_addr(char *inetString) { unsigned long val, base, n; char c; unsigned long parts[MAX_PARTS]; unsigned long *pp; /* If null inet string */ if (inetString == NULL) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if null inet string */ /* Initialize locals */ pp = parts; again: val = 0; base = 10; /* If zero prefix */ if (*inetString == '0') { base = 8; inetString++; /* If hexadecimal prefix */ if ( (*inetString == 'x') || (*inetString == 'X') ) { base = 16; inetString++; } /* End if hexadecimal prefix */ } /* End if zero prefix */ /* While not string terminator */ while ( (c = *inetString) ) { /* If digit */ if ( __isdigit((int) c) ) { val = (val * base) + (c - '0'); inetString++; continue; } /* End if digit */ /* If hexadecimal digit */ if ( __isxdigit((int) c) ) { val = (val << 4) + (c + 10 - (__islower((int) c) ? 'a' : 'A')); inetString++; continue; } /* End if hexadecimal digit */ /* If here break loop */ break; } /* End while not string terminator */ /* If dot found */ if (*inetString == '.') { /* If string to large or value to large */ if ( (pp >= parts + (MAX_PARTS - 1)) || (val > 0xff) ) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if string to large or value to large */ /* Store value */ *pp++ = val; /* Advance */ inetString++; /* Find next value */ goto again; } /* End if dot found */ /* If trailing character */ if ( (*inetString) && !(__isspace((int) *inetString)) ) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if trailing character */ /* Store value */ *pp++ = val; n = pp - parts; /* Select parts number */ switch (n) { /* 32 bit address */ case 1: val = parts[0]; break; /* 8.24 bits address */ case 2: /* If value to large */ if (val > 0xffffff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | parts[1]; break; /* 8.8.16 bits address */ case 3: /* If value to large */ if (val > 0xffff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | (parts[1] << 16) | parts[2]; break; /* 8.8.8.8 bits */ case 4: /* If value to large */ if (val > 0xff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]; break; default: errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End select part number */ return htonl(val); }
static int __toupper(int c) { return __islower(c) ? c - 'a' + 'A' : c; }