FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/*
 * Pretty-print an interval into the given buffer, in a human-friendly format.
 */
Pretty-print an interval into the given buffer, in a human-friendly format.
Pretty - print an interval into the given buffer in a human - friendly format .
static char *
prettyinterval(
	char *buf,
	size_t cb,
	long diff
	)
{
	if (diff <= 0) {
		buf[0] = '-';
		buf[1] = 0;
		return buf;
	}
	if (diff <= 2048) {
		snprintf(buf, cb, "%ld", diff);
		return buf;
	}
	diff = (diff + 29) / 60;
	if (diff <= 300) {
		snprintf(buf, cb, "%ldm", diff);
		return buf;
	}
	diff = (diff + 29) / 60;
	if (diff <= 96) {
		snprintf(buf, cb, "%ldh", diff);
		return buf;
	}
	diff = (diff + 11) / 24;
	snprintf(buf, cb, "%ldd", diff);
	return buf;
}
static char * prettyinterval ( char * buf , size_t cb , long diff ) { if ( diff <= 0 ) { buf [ 0 ] = ' ' ; buf [ 1 ] = 0 ; return buf ; } if ( diff <= 2048 ) { snprintf ( buf , cb , " " , diff ) ; return buf ; } diff = ( diff + 29 ) / 60 ; if ( diff <= 300 ) { snprintf ( buf , cb , " " , diff ) ; return buf ; } diff = ( diff + 29 ) / 60 ; if ( diff <= 96 ) { snprintf ( buf , cb , " " , diff ) ; return buf ; } diff = ( diff + 11 ) / 24 ; snprintf ( buf , cb , " " , diff ) ; return buf ; }
Pretty-print an interval into the given buffer, in a human-friendly format.
Pretty - print an interval into the given buffer in a human - friendly format .