FreeBSD/contrib/ntp/ntpd/ntp_leapsec.c
/* [internal] Given a time stamp for a leap insertion (the exact begin
 * of the new leap era), create new leap frame and put it into the
 * table. This is the work horse for reading a leap file and getting a
 * leap second update via authenticated network packet.
 */
[internal] Given a time stamp for a leap insertion (the exact begin
of the new leap era), create new leap frame and put it into the
table. This is the work horse for reading a leap file and getting a
leap second update via authenticated network packet.
[ internal ] Given a time stamp for a leap insertion ( the exact begin of the new leap era ) create new leap frame and put it into the table . This is the work horse for reading a leap file and getting a leap second update via authenticated network packet .
int
leapsec_raw(
	leap_table_t * pt,
	const vint64 * ttime,
	int            taiof,
	int            dynls)
{
	vint64		starttime;
	struct calendar	fts;
	leap_info_t	li;
	if (pt->head.size) {
		int cmp = ucmpv64(ttime, &pt->info[0].ttime);
		if (cmp == 0)
			cmp -= (taiof != pt->info[0].taiof);
		if (cmp < 0) {
			errno = ERANGE;
			return FALSE;
		}
		if (cmp == 0)
			return TRUE;
	}
	ntpcal_ntp64_to_date(&fts, ttime);
	if (fts.monthday != 1 || fts.hour || fts.minute || fts.second) {
		errno = EINVAL;
		return FALSE;
	}
	fts.month--; 
	starttime = ntpcal_date_to_ntp64(&fts);
	li.ttime = *ttime;
	li.stime = ttime->D_s.lo - starttime.D_s.lo;
	li.taiof = (int16_t)taiof;
	li.dynls = (dynls != 0);
	return add_range(pt, &li);
}
int leapsec_raw ( leap_table_t * pt , const vint64 * ttime , int taiof , int dynls ) { vint64 starttime ; struct calendar fts ; leap_info_t li ; if ( pt -> head . size ) { int cmp = ucmpv64 ( ttime , & pt -> info [ 0 ] . ttime ) ; if ( cmp == 0 ) cmp -= ( taiof != pt -> info [ 0 ] . taiof ) ; if ( cmp < 0 ) { errno = ERANGE ; return FALSE ; } if ( cmp == 0 ) return TRUE ; } ntpcal_ntp64_to_date ( & fts , ttime ) ; if ( fts . monthday != 1 || fts . hour || fts . minute || fts . second ) { errno = EINVAL ; return FALSE ; } fts . month -- ; starttime = ntpcal_date_to_ntp64 ( & fts ) ; li . ttime = * ttime ; li . stime = ttime -> D_s . lo - starttime . D_s . lo ; li . taiof = ( int16_t ) taiof ; li . dynls = ( dynls != 0 ) ; return add_range ( pt , & li ) ; }
[internal] Given a time stamp for a leap insertion (the exact begin
 of the new leap era), create new leap frame and put it into the
 table.
[ internal ] Given a time stamp for a leap insertion ( the exact begin of the new leap era ) create new leap frame and put it into the table .
/*BOOL*/ /* Check that we either extend the table or get a duplicate of
	 * the latest entry. The latter is a benevolent overwrite with
	 * identical data and could happen if we get an autokey message
	 * that extends the lifetime of the current leapsecond table.
	 * Otherwise paranoia rulez!
	 */ /* If this does not match the exact month start, bail out. */ /* was in range 1..12, no overflow here! */