2014-11-28 14:58:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
// assumes endptr != NULL
|
|
|
|
// doesn't check for sign
|
|
|
|
// doesn't check for base-prefix
|
|
|
|
long long int strtoll(const char *nptr, char **endptr, int base) {
|
|
|
|
long long val = 0;
|
|
|
|
|
|
|
|
for (; *nptr; nptr++) {
|
|
|
|
int v = *nptr;
|
|
|
|
if ('0' <= v && v <= '9') {
|
|
|
|
v -= '0';
|
|
|
|
} else if ('A' <= v && v <= 'Z') {
|
|
|
|
v -= 'A' - 10;
|
|
|
|
} else if ('a' <= v && v <= 'z') {
|
|
|
|
v -= 'a' - 10;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (v >= base) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
val = val * base + v;
|
|
|
|
}
|
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
*endptr = (char *)nptr;
|
2014-11-28 14:58:25 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|