FreeBSD/contrib/ntp/ntpd/ntp_leapsec.c
/* ---------------------------------------------------------------------
 * Load a leap second file and check expiration on the go
 */
Load a leap second file and check expiration on the go
Load a leap second file and check expiration on the go
int
leapsec_load(
	leap_table_t * pt  ,
	leapsec_reader func,
	void *         farg,
	int            use_build_limit)
{
	char   *cp, *ep, linebuf[50];
	vint64 ttime, limit;
	long   taiof;
	struct calendar build;
	leapsec_clear(pt);
	if (use_build_limit && ntpcal_get_build_date(&build)) {
		build.year -= 10;
		limit = ntpcal_date_to_ntp64(&build);
	} else {
		memset(&limit, 0, sizeof(limit));
	}
	while (get_line(func, farg, linebuf, sizeof(linebuf))) {
		cp = linebuf;
		if (*cp == '#') {
			cp++;
			if (*cp == '@') {
				cp = skipws(cp+1);
				pt->head.expire = strtouv64(cp, &ep, 10);
				if (parsefail(cp, ep))
					goto fail_read;
				pt->lsig.etime = pt->head.expire.D_s.lo;
			} else if (*cp == '$') {
				cp = skipws(cp+1);
				pt->head.update = strtouv64(cp, &ep, 10);
				if (parsefail(cp, ep))
					goto fail_read;
			}
		} else if (isdigit((u_char)*cp)) {
			ttime = strtouv64(cp, &ep, 10);
			if (parsefail(cp, ep))
				goto fail_read;
			cp = skipws(ep);
			taiof = strtol(cp, &ep, 10);
			if (   parsefail(cp, ep)
			    || taiof > SHRT_MAX || taiof < SHRT_MIN)
				goto fail_read;
			if (ucmpv64(&ttime, &limit) >= 0) {
				if (!leapsec_raw(pt, &ttime,
						 taiof, FALSE))
					goto fail_insn;
			} else {
				pt->head.base_tai = (int16_t)taiof;
			}
			pt->lsig.ttime = ttime.D_s.lo;
			pt->lsig.taiof = (int16_t)taiof;
		}
	}
	return TRUE;
fail_read:
	errno = EILSEQ;
fail_insn:
	leapsec_clear(pt);
	return FALSE;
}
int leapsec_load ( leap_table_t * pt , leapsec_reader func , void * farg , int use_build_limit ) { char * cp , * ep , linebuf [ 50 ] ; vint64 ttime , limit ; long taiof ; struct calendar build ; leapsec_clear ( pt ) ; if ( use_build_limit && ntpcal_get_build_date ( & build ) ) { build . year -= 10 ; limit = ntpcal_date_to_ntp64 ( & build ) ; } else { memset ( & limit , 0 , sizeof ( limit ) ) ; } while ( get_line ( func , farg , linebuf , sizeof ( linebuf ) ) ) { cp = linebuf ; if ( * cp == ' ' ) { cp ++ ; if ( * cp == ' ' ) { cp = skipws ( cp + 1 ) ; pt -> head . expire = strtouv64 ( cp , & ep , 10 ) ; if ( parsefail ( cp , ep ) ) goto fail_read ; pt -> lsig . etime = pt -> head . expire . D_s . lo ; } else if ( * cp == ' ' ) { cp = skipws ( cp + 1 ) ; pt -> head . update = strtouv64 ( cp , & ep , 10 ) ; if ( parsefail ( cp , ep ) ) goto fail_read ; } } else if ( isdigit ( ( u_char ) * cp ) ) { ttime = strtouv64 ( cp , & ep , 10 ) ; if ( parsefail ( cp , ep ) ) goto fail_read ; cp = skipws ( ep ) ; taiof = strtol ( cp , & ep , 10 ) ; if ( parsefail ( cp , ep ) || taiof > SHRT_MAX || taiof < SHRT_MIN ) goto fail_read ; if ( ucmpv64 ( & ttime , & limit ) >= 0 ) { if ( ! leapsec_raw ( pt , & ttime , taiof , FALSE ) ) goto fail_insn ; } else { pt -> head . base_tai = ( int16_t ) taiof ; } pt -> lsig . ttime = ttime . D_s . lo ; pt -> lsig . taiof = ( int16_t ) taiof ; } } return TRUE ; fail_read : errno = EILSEQ ; fail_insn : leapsec_clear ( pt ) ; return FALSE ; }
Load a leap second file and check expiration on the go
Load a leap second file and check expiration on the go
/*BOOL*/ /* don't prune everything -- permit the last 10yrs
		 * before build.
		 */