|
|
@ -2,19 +2,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
static const unsigned long maxlong = ((unsigned long)-1)>>1;
|
|
|
|
static const unsigned long maxlong = ((unsigned long)-1)>>1;
|
|
|
|
|
|
|
|
|
|
|
|
size_t scan_longn(const char *src,size_t n,long *dest) {
|
|
|
|
size_t scan_longn(const char *src,size_t len,long *dest) {
|
|
|
|
register const char *tmp;
|
|
|
|
register const char *tmp;
|
|
|
|
register long int l;
|
|
|
|
register long int l;
|
|
|
|
register unsigned char c;
|
|
|
|
register unsigned char c;
|
|
|
|
unsigned int neg;
|
|
|
|
unsigned int neg;
|
|
|
|
int ok;
|
|
|
|
int ok;
|
|
|
|
if (!n--) return 0;
|
|
|
|
if (!len) return 0;
|
|
|
|
tmp=src; l=0; ok=0; neg=0;
|
|
|
|
tmp=src; l=0; ok=0; neg=0;
|
|
|
|
switch (*tmp) {
|
|
|
|
switch (*tmp) {
|
|
|
|
case '-': neg=1; /* fall through */
|
|
|
|
case '-': neg=1; /* fall through */
|
|
|
|
case '+': ++tmp;
|
|
|
|
case '+': ++tmp; --len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n-->0 && (c=(unsigned char)(*tmp-'0'))<10) {
|
|
|
|
while (len-->0 && (c=(unsigned char)(*tmp-'0'))<10) {
|
|
|
|
unsigned long int n;
|
|
|
|
unsigned long int n;
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ >= 5)
|
|
|
|
#if defined(__GNUC__) && (__GNUC__ >= 5)
|
|
|
|
if (__builtin_mul_overflow(l,10,&n) || __builtin_add_overflow(n,c,&n))
|
|
|
|
if (__builtin_mul_overflow(l,10,&n) || __builtin_add_overflow(n,c,&n))
|
|
|
|