FreeBSD/contrib/ntp/ntpd/ntp_leapsec.c
/* [internal] reload the table limits around the given time stamp. This
 * is where the real work is done when it comes to table lookup and
 * evaluation. Some care has been taken to have correct code for dealing
 * with boundary conditions and empty tables.
 *
 * In electric mode, transition and trip time are the same. In dumb
 * mode, the difference of the TAI offsets must be taken into account
 * and trip time and transition time become different. The difference
 * becomes the warping distance when the trip time is reached.
 */
[internal] reload the table limits around the given time stamp. This
is where the real work is done when it comes to table lookup and
evaluation. Some care has been taken to have correct code for dealing
with boundary conditions and empty tables.

In electric mode, transition and trip time are the same. In dumb
mode, the difference of the TAI offsets must be taken into account
and trip time and transition time become different. The difference
becomes the warping distance when the trip time is reached.
[ internal ] reload the table limits around the given time stamp . This is where the real work is done when it comes to table lookup and evaluation . Some care has been taken to have correct code for dealing with boundary conditions and empty tables . In electric mode transition and trip time are the same . In dumb mode the difference of the TAI offsets must be taken into account and trip time and transition time become different . The difference becomes the warping distance when the trip time is reached .
static void
reload_limits(
	leap_table_t * pt,
	const vint64 * ts)
{
	int idx;
	for (idx = 0; idx != pt->head.size; idx++)
		if (ucmpv64(ts, &pt->info[idx].ttime) >= 0)
			break;
	if (idx >= pt->head.size) {
		memset(&pt->head.ebase, 0x00, sizeof(vint64));
		pt->head.this_tai = pt->head.base_tai;
	} else {
		pt->head.ebase    = pt->info[idx].ttime;
		pt->head.this_tai = pt->info[idx].taiof;
	}
	if (--idx >= 0) {
		pt->head.next_tai = pt->info[idx].taiof;
		pt->head.dynls    = pt->info[idx].dynls;
		pt->head.ttime    = pt->info[idx].ttime;
		if (_electric)
			pt->head.dtime = pt->head.ttime;
                else
			pt->head.dtime = addv64i32(
				&pt->head.ttime,
				pt->head.next_tai - pt->head.this_tai);
		pt->head.stime = subv64u32(
			&pt->head.ttime, pt->info[idx].stime);
	} else {
		memset(&pt->head.ttime, 0xFF, sizeof(vint64));
		pt->head.stime    = pt->head.ttime;
		pt->head.dtime    = pt->head.ttime;
		pt->head.next_tai = pt->head.this_tai;
		pt->head.dynls    = 0;
	}
}
static void reload_limits ( leap_table_t * pt , const vint64 * ts ) { int idx ; for ( idx = 0 ; idx != pt -> head . size ; idx ++ ) if ( ucmpv64 ( ts , & pt -> info [ idx ] . ttime ) >= 0 ) break ; if ( idx >= pt -> head . size ) { memset ( & pt -> head . ebase , 0x00 , sizeof ( vint64 ) ) ; pt -> head . this_tai = pt -> head . base_tai ; } else { pt -> head . ebase = pt -> info [ idx ] . ttime ; pt -> head . this_tai = pt -> info [ idx ] . taiof ; } if ( -- idx >= 0 ) { pt -> head . next_tai = pt -> info [ idx ] . taiof ; pt -> head . dynls = pt -> info [ idx ] . dynls ; pt -> head . ttime = pt -> info [ idx ] . ttime ; if ( _electric ) pt -> head . dtime = pt -> head . ttime ; else pt -> head . dtime = addv64i32 ( & pt -> head . ttime , pt -> head . next_tai - pt -> head . this_tai ) ; pt -> head . stime = subv64u32 ( & pt -> head . ttime , pt -> info [ idx ] . stime ) ; } else { memset ( & pt -> head . ttime , 0xFF , sizeof ( vint64 ) ) ; pt -> head . stime = pt -> head . ttime ; pt -> head . dtime = pt -> head . ttime ; pt -> head . next_tai = pt -> head . this_tai ; pt -> head . dynls = 0 ; } }
[internal] reload the table limits around the given time stamp.
[ internal ] reload the table limits around the given time stamp .
/* Get full time and search the true lower bound. Use a
	 * simple loop here, since the number of entries does
	 * not warrant a binary search. This also works for an empty
	 * table, so there is no shortcut for that case.
	 */ /* get time limits with proper bound conditions. Note that the
	 * bounds of the table will be observed even if the table is
	 * empty -- no undefined condition must arise from this code.
	 */