Lines Matching +full:ch +full:- +full:func

2  * ntp_leapsec.c - leap second processing for NTPD
6 * ----------------------------------------------------------------------
26 /* ---------------------------------------------------------------------
84 /* ------------------------------------------------------------------ */
111 /* ------------------------------------------------------------------ */
121 /* ------------------------------------------------------------------ */
144 /* ---------------------------------------------------------------------
151 memset(&pt->lsig, 0, sizeof(pt->lsig));
152 memset(&pt->head, 0, sizeof(pt->head));
156 /* ---------------------------------------------------------------------
162 leapsec_reader func,
174 /* don't prune everything -- permit the last 10yrs
177 build.year -= 10;
183 while (get_line(func, farg, linebuf, sizeof(linebuf))) {
189 pt->head.expire = strtouv64(cp, &ep, 10);
192 pt->lsig.etime = pt->head.expire.D_s.lo;
195 pt->head.update = strtouv64(cp, &ep, 10);
213 pt->head.base_tai = (int16_t)taiof;
215 pt->lsig.ttime = ttime.D_s.lo;
216 pt->lsig.taiof = (int16_t)taiof;
228 /* ---------------------------------------------------------------------
229 * Dump a table in human-readable format. Use 'fprintf' and a FILE
235 leapsec_dumper func,
242 ntpcal_ntp64_to_date(&ttb, &pt->head.expire);
243 (*func)(farg, "leap table (%u entries) expires at %04u-%02u-%02u:\n",
244 pt->head.size,
246 idx = pt->head.size;
247 while (idx-- != 0) {
248 ts = pt->info[idx].ttime;
250 ts = subv64u32(&ts, pt->info[idx].stime);
253 (*func)(farg, "%04u-%02u-%02u [%c] (%04u-%02u-%02u) - %d\n",
255 "-*"[pt->info[idx].dynls != 0],
257 pt->info[idx].taiof);
282 if (ucmpv64(&ts64, &pt->head.ebase) < 0) {
288 } else if (ucmpv64(&ts64, &pt->head.dtime) >= 0) {
304 last = addv64i32(&pt->head.dtime, 3); /* get boundary */
310 last = pt->head.ttime;
311 qr->warped = (int16_t)(last.D_s.lo -
312 pt->head.dtime.D_s.lo);
313 next = addv64i32(&ts64, qr->warped);
315 fired = ucmpv64(&pt->head.ebase, &last) == 0;
320 qr->warped = 0;
325 qr->tai_offs = pt->head.this_tai;
326 qr->ebase = pt->head.ebase;
327 qr->ttime = pt->head.ttime;
330 if (ucmpv64(&ts64, &pt->head.stime) < 0)
334 due32 = pt->head.dtime.D_s.lo;
336 qr->tai_diff = pt->head.next_tai - pt->head.this_tai;
337 qr->ddist = due32 - ts32;
338 qr->dynamic = pt->head.dynls;
339 qr->proximity = LSPROX_SCHEDULE;
342 if (!betweenu32(due32 - SECSPERDAY, ts32, due32))
345 qr->proximity = LSPROX_ANNOUNCE;
346 if (!betweenu32(due32 - 10, ts32, due32))
350 qr->proximity = LSPROX_ALERT;
354 /* ------------------------------------------------------------------ */
370 /* ------------------------------------------------------------------ */
380 qr->tai_offs = pt->head.this_tai;
381 qr->tai_diff = pt->head.next_tai - pt->head.this_tai;
382 qr->ebase = pt->head.ebase;
383 qr->ttime = pt->head.ttime;
384 qr->dynamic = pt->head.dynls;
386 return ucmpv64(&pt->head.ttime, &pt->head.stime) >= 0;
389 /* ------------------------------------------------------------------ */
397 /* ------------------------------------------------------------------ */
465 if (pt->head.size)
467 logPrefix, fname, lstostr(&pt->head.expire),
468 lstostr(&pt->info[0].ttime), pt->info[0].taiof);
472 logPrefix, fname, lstostr(&pt->head.expire),
473 pt->head.base_tai);
478 /* ------------------------------------------------------------------ */
506 && sb_old->st_mtime == sb_new.st_mtime
507 && sb_old->st_ctime == sb_new.st_ctime
516 * coverity raises a TOCTOU (time-of-check/time-of-use) issue
543 /* ------------------------------------------------------------------ */
551 memcpy(psig, &pt->lsig, sizeof(leap_signature_t));
554 /* ------------------------------------------------------------------ */
565 return ucmpv64(&limit, &pt->head.expire) >= 0;
568 /* ------------------------------------------------------------------ */
579 limit = subv64(&pt->head.expire, &limit);
583 /* ------------------------------------------------------------------ */
584 #if 0 /* currently unused -- possibly revived later */
605 if ( ucmpv64(&et64, &pt->head.expire) <= 0
609 pt->lsig.etime = etime;
610 pt->lsig.ttime = ttime;
611 pt->lsig.taiof = (int16_t)total;
613 pt->head.expire = et64;
619 /* ------------------------------------------------------------------ */
635 /* ------------------------------------------------------------------ */
651 * offset is bigger than 10s. That was in 1972 -- we don't want
654 if (pt->head.base_tai != 0 || tai_offset < 10)
666 for (idx = 0; idx != pt->head.size; idx++)
667 if ( ! pt->info[idx].dynls)
679 era.ttime = addv64i32(&era.ttime, -20);
684 tai_offset -= era.taiof;
687 pt->head.base_tai += tai_offset;
688 pt->head.this_tai += tai_offset;
689 pt->head.next_tai += tai_offset;
692 for (idx = 0; idx != pt->head.size; idx++)
693 pt->info[idx].taiof += tai_offset;
715 memset(&pt->head.ebase, 0xFF, sizeof(vint64));
716 pt->head.stime = pt->head.ebase;
717 pt->head.ttime = pt->head.ebase;
718 pt->head.dtime = pt->head.ebase;
734 * leap second removal. So we decide on the sign -- if the first
743 if (pt->head.size == 0) {
744 if (pi->taiof >= 0)
745 pt->head.base_tai = pi->taiof - 1;
747 pt->head.base_tai = pi->taiof + 1;
748 } else if (pt->head.size >= MAX_HIST) {
749 pt->head.size = MAX_HIST - 1;
750 pt->head.base_tai = pt->info[pt->head.size].taiof;
754 memmove(pt->info+1, pt->info, pt->head.size*sizeof(*pt->info));
755 pt->info[0] = *pi;
756 pt->head.size++;
758 /* invalidate the cached limit data -- we might have news ;-)
772 * EOL-marker ('\n') is *not* stored in the buffer.
779 leapsec_reader func,
784 int ch;
792 while (EOF != (ch = (*func)(farg)) && '\n' != ch)
794 size--;
795 *ptr++ = (char)ch;
798 while (ptr != buff && isspace((u_char)ptr[-1]))
799 ptr--;
801 return (ptr == buff && ch == EOF) ? NULL : buff;
850 for (idx = 0; idx != pt->head.size; idx++)
851 if (ucmpv64(ts, &pt->info[idx].ttime) >= 0)
856 * empty -- no undefined condition must arise from this code.
858 if (idx >= pt->head.size) {
859 memset(&pt->head.ebase, 0x00, sizeof(vint64));
860 pt->head.this_tai = pt->head.base_tai;
862 pt->head.ebase = pt->info[idx].ttime;
863 pt->head.this_tai = pt->info[idx].taiof;
865 if (--idx >= 0) {
866 pt->head.next_tai = pt->info[idx].taiof;
867 pt->head.dynls = pt->info[idx].dynls;
868 pt->head.ttime = pt->info[idx].ttime;
871 pt->head.dtime = pt->head.ttime;
873 pt->head.dtime = addv64i32(
874 &pt->head.ttime,
875 pt->head.next_tai - pt->head.this_tai);
877 pt->head.stime = subv64u32(
878 &pt->head.ttime, pt->info[idx].stime);
881 memset(&pt->head.ttime, 0xFF, sizeof(vint64));
882 pt->head.stime = pt->head.ttime;
883 pt->head.dtime = pt->head.ttime;
884 pt->head.next_tai = pt->head.this_tai;
885 pt->head.dynls = 0;
890 * This is a cut-down version the algorithm used to reload the table
903 for (idx = 0; idx != pt->head.size; idx++)
904 if (ucmpv64(ts, &pt->info[idx].ttime) >= 0)
907 if (idx >= pt->head.size) {
908 memset(&into->ebase, 0x00, sizeof(vint64));
909 into->taiof = pt->head.base_tai;
911 into->ebase = pt->info[idx].ttime;
912 into->taiof = pt->info[idx].taiof;
914 if (--idx >= 0)
915 into->ttime = pt->info[idx].ttime;
917 memset(&into->ttime, 0xFF, sizeof(vint64));
927 * insert a leap second into the current history -- only appending
944 if ( ucmpv64(now64, &pt->head.expire) < 0
945 || (pt->head.size && ucmpv64(now64, &pt->info[0].ttime) <= 0)) {
969 li.stime = ttime.D_s.lo - starttime.D_s.lo;
970 li.taiof = (pt->head.size ? pt->info[0].taiof : pt->head.base_tai)
971 + (insert ? 1 : -1);
998 if (pt->head.size) {
999 int cmp = ucmpv64(ttime, &pt->info[0].ttime);
1001 cmp -= (taiof != pt->info[0].taiof);
1016 fts.month--; /* was in range 1..12, no overflow here! */
1019 li.stime = ttime->D_s.lo - starttime.D_s.lo;
1025 /* [internal] Do a wrap-around save range inclusion check.
1027 * handling of an overflow / wrap-around.
1054 * without leading zeros. This makes reading them back as hex-encoded
1080 for (di=3; di >= 0; --di) {
1081 mac->hv[wi*4 + di] =
1098 unsigned char ch;
1100 while ('\0' != (ch = *cp++) && '#' != ch)
1101 if (isdigit(ch)) {
1102 text[tlen++] = ch;
1103 tlen &= (sizeof(text)-1);
1118 leapsec_reader func,
1124 int hlseen = -1;
1127 while (get_line(func, farg, line, sizeof(line))) {
1150 * lstostr - prettyprint NTP seconds
1161 if ( ! (ts->d_s.hi >= 0 && ntpcal_ntp64_to_date(&tm, ts) >= 0))
1162 snprintf(buf, LIB_BUFLENGTH, "%s", "9999-12-31T23:59:59Z");
1164 snprintf(buf, LIB_BUFLENGTH, "%04d-%02d-%02dT%02d:%02d:%02dZ",
1182 /* -*- that's all folks! -*- */