#include <config.h>
#include <ctype.h>
#include <isc/string.h>
static char digits[] = "0123456789abcdefghijklmnoprstuvwxyz";
isc_uint64_t
isc_string_touint64(char *source, char **end, int base) {
isc_uint64_t tmp;
isc_uint64_t overflow;
char *s = source;
char *o;
char c;
if ((base < 0) || (base == 1) || (base > 36)) {
*end = source;
return (0);
}
while (*s != 0 && isascii(*s&0xff) && isspace(*s&0xff))
s++;
if (*s == '+' )
s++;
if (base == 0) {
if (*s == '0' && (*(s+1) == 'X' || *(s+1) == 'x')) {
s += 2;
base = 16;
} else if (*s == '0')
base = 8;
else
base = 10;
}
if (*s == 0) {
*end = source;
return (0);
}
overflow = ~0;
overflow /= base;
tmp = 0;
while ((c = *s) != 0) {
c = tolower(c);
if ((o = strchr(digits, c)) == NULL) {
*end = s;
return (tmp);
}
if ((o - digits) >= base) {
*end = s;
return (tmp);
}
if (tmp > overflow) {
*end = source;
return (0);
}
tmp *= base;
if ((tmp + (o - digits)) < tmp) {
*end = source;
return (0);
}
tmp += o - digits;
s++;
}
*end = s;
return (tmp);
}
char *
isc_string_separate(char **stringp, const char *delim) {
char *string = *stringp;
char *s;
const char *d;
char sc, dc;
if (string == NULL)
return (NULL);
for (s = string; (sc = *s) != '\0'; s++)
for (d = delim; (dc = *d) != '\0'; d++)
if (sc == dc) {
*s++ = '\0';
*stringp = s;
return (string);
}
*stringp = NULL;
return (string);
}