FreeBSD/sbin/ipfw/dummynet.c
/*
 * returns -1 if s is not a valid time, otherwise, return time in us
 */
1 if s is not a valid time, otherwise, return time in us
1 if s is not a valid time otherwise return time in us
static long
time_to_us(const char *s)
{
	int i, dots = 0;
	int len = strlen(s);
	char strt[16]="", stru[16]="";
	if (len>15)
		return -1;
	for (i = 0; i<len && (isdigit(s[i]) || s[i]=='.') ; i++)
		if (s[i]=='.') {
			if (dots)
				return -1;
			else
				dots++;
		}
	if (!i)
		return -1;
	strncpy(strt, s, i);
	if (i<len)
		strcpy(stru, s+i);
	else
		strcpy(stru, "ms");
	if (!strcasecmp(stru, "us"))
		return atol(strt);
	if (!strcasecmp(stru, "ms"))
		return (strtod(strt, NULL) * 1000);
	if (!strcasecmp(stru, "s"))
		return (strtod(strt, NULL)*1000000);
	return -1;
}
static long time_to_us ( const char * s ) { int i , dots = 0 ; int len = strlen ( s ) ; char strt [ 16 ] = " " , stru [ 16 ] = " " ; if ( len > 15 ) return -1 ; for ( i = 0 ; i < len && ( isdigit ( s [ i ] ) || s [ i ] == ' ' ) ; i ++ ) if ( s [ i ] == ' ' ) { if ( dots ) return -1 ; else dots ++ ; } if ( ! i ) return -1 ; strncpy ( strt , s , i ) ; if ( i < len ) strcpy ( stru , s + i ) ; else strcpy ( stru , " " ) ; if ( ! strcasecmp ( stru , " " ) ) return atol ( strt ) ; if ( ! strcasecmp ( stru , " " ) ) return ( strtod ( strt , NULL ) * 1000 ) ; if ( ! strcasecmp ( stru , " " ) ) return ( strtod ( strt , NULL ) * 1000000 ) ; return -1 ; }
returns -1 if s is not a valid time, otherwise, return time in us
returns - 1 if s is not a valid time otherwise return time in us