FreeBSD/sys/net/if_clone.c
/*
 * A utility function to extract unit numbers from interface names of
 * the form name###.
 *
 * Returns 0 on success and an error on failure.
 */
A utility function to extract unit numbers from interface names of
the form name###.

Returns 0 on success and an error on failure.
A utility function to extract unit numbers from interface names of the form name### . Returns 0 on success and an error on failure .
int
ifc_name2unit(const char *name, int *unit)
{
	const char	*cp;
	int		cutoff = INT_MAX / 10;
	int		cutlim = INT_MAX % 10;
	for (cp = name; *cp != '\0' && (*cp < '0' || *cp > '9'); cp++);
	if (*cp == '\0') {
		*unit = -1;
	} else if (cp[0] == '0' && cp[1] != '\0') {
		return (EINVAL);
	} else {
		for (*unit = 0; *cp != '\0'; cp++) {
			if (*cp < '0' || *cp > '9') {
				return (EINVAL);
			}
			if (*unit > cutoff ||
			    (*unit == cutoff && *cp - '0' > cutlim))
				return (EINVAL);
			*unit = (*unit * 10) + (*cp - '0');
		}
	}
	return (0);
}
int ifc_name2unit ( const char * name , int * unit ) { const char * cp ; int cutoff = INT_MAX / 10 ; int cutlim = INT_MAX % 10 ; for ( cp = name ; * cp != ' \0 ' && ( * cp < ' ' || * cp > ' ' ) ; cp ++ ) ; if ( * cp == ' \0 ' ) { * unit = -1 ; } else if ( cp [ 0 ] == ' ' && cp [ 1 ] != ' \0 ' ) { return ( EINVAL ) ; } else { for ( * unit = 0 ; * cp != ' \0 ' ; cp ++ ) { if ( * cp < ' ' || * cp > ' ' ) { return ( EINVAL ) ; } if ( * unit > cutoff || ( * unit == cutoff && * cp - ' ' > cutlim ) ) return ( EINVAL ) ; * unit = ( * unit * 10 ) + ( * cp - ' ' ) ; } } return ( 0 ) ; }
A utility function to extract unit numbers from interface names of
 the form name###.
A utility function to extract unit numbers from interface names of the form name### .
/* Disallow leading zeroes. */ /* Bogus unit number. */