contrib/mdocml/mandoc.c
/*
 * Convert a string to a long that may not be <0.
 * If the string is invalid, or is less than 0, return -1.
 */
Convert a string to a long that may not be <0.
If the string is invalid, or is less than 0, return -1.
Convert a string to a long that may not be <0 . If the string is invalid or is less than 0 return - 1 .
int
mandoc_strntoi(const char *p, size_t sz, int base)
{
	char		 buf[32];
	char		*ep;
	long		 v;
	if (sz > 31)
		return -1;
	memcpy(buf, p, sz);
	buf[(int)sz] = '\0';
	errno = 0;
	v = strtol(buf, &ep, base);
	if (buf[0] == '\0' || *ep != '\0')
		return -1;
	if (v > INT_MAX)
		v = INT_MAX;
	if (v < INT_MIN)
		v = INT_MIN;
	return (int)v;
}
int mandoc_strntoi ( const char * p , size_t sz , int base ) { char buf [ 32 ] ; char * ep ; long v ; if ( sz > 31 ) return -1 ; memcpy ( buf , p , sz ) ; buf [ ( int ) sz ] = ' \0 ' ; errno = 0 ; v = strtol ( buf , & ep , base ) ; if ( buf [ 0 ] == ' \0 ' || * ep != ' \0 ' ) return -1 ; if ( v > INT_MAX ) v = INT_MAX ; if ( v < INT_MIN ) v = INT_MIN ; return ( int ) v ; }
Convert a string to a long that may not be <0.
Convert a string to a long that may not be <0 .