src/standard.c
int strl2llrc(const char *s, int len, long long *ret)
{
	long long i = 0;
	int j;

	if (!len)
		return 1;

	if (*s != '-') {
		/* positive number */
		while (len-- > 0) {
			j = (*s++) - '0';
			if (j > 9)              return 1; /* invalid char */
			if (i > LLONG_MAX / 10LL) return 1; /* check for multiply overflow */
			i = i * 10LL;
			if (i + j < i)          return 1; /* check for addition overflow */
			i = i + j;
		}
	} else {
		/* negative number */
		s++;
		while (--len > 0) {
			j = (*s++) - '0';
			if (j > 9)              return 1; /* invalid char */
			if (i < LLONG_MIN / 10LL) return 1; /* check for multiply overflow */
			i = i * 10LL;
			if (i - j > i)          return 1; /* check for subtract overflow */
			i = i - j;
		}
	}
	*ret = i;
	return 0;
}
/* This function reads exactly <len> chars from <s> and converts them to a
 * signed integer which it stores into <ret>. It accurately detects any error
 * (truncated string, invalid chars, overflows). It is meant to be used in
 * applications designed for hostile environments. It returns zero when the
 * number has successfully been converted, non-zero otherwise. When an error
 * is returned, the <ret> value is left untouched. It is about 3 times slower
 * than str2irc().
 */
This function reads exactly  chars from  and converts them to a
signed integer which it stores into . It accurately detects any error
(truncated string, invalid chars, overflows). It is meant to be used in
applications designed for hostile environments. It returns zero when the
number has successfully been converted, non-zero otherwise. When an error
is returned, the  value is left untouched. It is about 3 times slower
than str2irc().
This function reads exactly chars from and converts them to a signed integer which it stores into . It accurately detects any error ( truncated string invalid chars overflows ) . It is meant to be used in applications designed for hostile environments . It returns zero when the number has successfully been converted non - zero otherwise . When an error is returned the value is left untouched . It is about 3 times slower than str2irc () .
int strl2llrc(const char *s, int len, long long *ret)
{
	long long i = 0;
	int j;
	if (!len)
		return 1;
	if (*s != '-') {
		while (len-- > 0) {
			j = (*s++) - '0';
			if (j > 9)              return 1; 
			if (i > LLONG_MAX / 10LL) return 1; 
			i = i * 10LL;
			if (i + j < i)          return 1; 
			i = i + j;
		}
	} else {
		s++;
		while (--len > 0) {
			j = (*s++) - '0';
			if (j > 9)              return 1; 
			if (i < LLONG_MIN / 10LL) return 1; 
			i = i * 10LL;
			if (i - j > i)          return 1; 
			i = i - j;
		}
	}
	*ret = i;
	return 0;
}
int strl2llrc ( const char * s , int len , long long * ret ) { long long i = 0 ; int j ; if ( ! len ) return 1 ; if ( * s != ' ' ) { while ( len -- > 0 ) { j = ( * s ++ ) - ' ' ; if ( j > 9 ) return 1 ; if ( i > LLONG_MAX / 10LL ) return 1 ; i = i * 10LL ; if ( i + j < i ) return 1 ; i = i + j ; } } else { s ++ ; while ( -- len > 0 ) { j = ( * s ++ ) - ' ' ; if ( j > 9 ) return 1 ; if ( i < LLONG_MIN / 10LL ) return 1 ; i = i * 10LL ; if ( i - j > i ) return 1 ; i = i - j ; } } * ret = i ; return 0 ; }
This function reads exactly <len> chars from <s> and converts them to a
 signed integer which it stores into <ret>.
This function reads exactly <len > chars from <s > and converts them to a signed integer which it stores into <ret > .
/* positive number */ /* invalid char */ /* check for multiply overflow */ /* check for addition overflow */ /* negative number */ /* invalid char */ /* check for multiply overflow */ /* check for subtract overflow */