2007-04-16 22:32:28 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-09-28 19:36:55 +00:00
|
|
|
int
|
|
|
|
hextobyte (const char *s)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if ( *s >= '0' && *s <= '9' )
|
|
|
|
c = 16 * (*s - '0');
|
|
|
|
else if ( *s >= 'A' && *s <= 'F' )
|
|
|
|
c = 16 * (10 + *s - 'A');
|
|
|
|
else if ( *s >= 'a' && *s <= 'f' )
|
|
|
|
c = 16 * (10 + *s - 'a');
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
s++;
|
|
|
|
if ( *s >= '0' && *s <= '9' )
|
|
|
|
c += *s - '0';
|
|
|
|
else if ( *s >= 'A' && *s <= 'F' )
|
|
|
|
c += 10 + *s - 'A';
|
|
|
|
else if ( *s >= 'a' && *s <= 'f' )
|
|
|
|
c += 10 + *s - 'a';
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
return c;
|
|
|
|
}
|
2007-04-16 22:32:28 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
ascii_toupper (int c)
|
|
|
|
{
|
|
|
|
if (c >= 'a' && c <= 'z')
|
|
|
|
c &= ~0x20;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ascii_tolower (int c)
|
|
|
|
{
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
c |= 0x20;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ascii_strcasecmp (const char *a, const char *b)
|
|
|
|
{
|
|
|
|
const unsigned char *p1 = (const unsigned char *)a;
|
|
|
|
const unsigned char *p2 = (const unsigned char *)b;
|
|
|
|
unsigned char c1, c2;
|
|
|
|
|
|
|
|
if (p1 == p2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c1 = ascii_tolower (*p1);
|
|
|
|
c2 = ascii_tolower (*p2);
|
|
|
|
|
|
|
|
if (c1 == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
++p1;
|
|
|
|
++p2;
|
|
|
|
}
|
|
|
|
while (c1 == c2);
|
|
|
|
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ascii_strncasecmp (const char *a, const char *b, size_t n)
|
|
|
|
{
|
|
|
|
const unsigned char *p1 = (const unsigned char *)a;
|
|
|
|
const unsigned char *p2 = (const unsigned char *)b;
|
|
|
|
unsigned char c1, c2;
|
|
|
|
|
|
|
|
if (p1 == p2 || !n )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c1 = ascii_tolower (*p1);
|
|
|
|
c2 = ascii_tolower (*p2);
|
|
|
|
|
|
|
|
if ( !--n || c1 == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
++p1;
|
|
|
|
++p2;
|
|
|
|
}
|
|
|
|
while (c1 == c2);
|
|
|
|
|
|
|
|
return c1 - c2;
|
|
|
|
}
|