diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-10-14 22:54:08 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-10-14 22:54:08 +0000 |
commit | 805729e206b7586c57483aa0f4a90f7e0e2c9661 (patch) | |
tree | 4d4afb75b73cd11c953853faa48dc4cc7f236380 /src/libstddjb | |
parent | 2e0421fc58922697f2bb51c428599fbd44055556 (diff) | |
download | skalibs-805729e206b7586c57483aa0f4a90f7e0e2c9661.tar.xz |
- Remove /etc/leapsecs.datv2.3.8.0
- Publish tools to create the leap second table as a .c
- Simplify functions using leap seconds
- rc for 2.3.8.0
Diffstat (limited to 'src/libstddjb')
-rw-r--r-- | src/libstddjb/djbtime-internal.h | 21 | ||||
-rw-r--r-- | src/libstddjb/leapsecs_add.c | 11 | ||||
-rw-r--r-- | src/libstddjb/leapsecs_here.c | 9 | ||||
-rw-r--r-- | src/libstddjb/leapsecs_init.c | 34 | ||||
-rw-r--r-- | src/libstddjb/leapsecs_sub.c | 10 | ||||
-rw-r--r-- | src/libstddjb/leapsecs_table.c | 39 | ||||
-rw-r--r-- | src/libstddjb/ltm64_from_utc.c | 2 | ||||
-rw-r--r-- | src/libstddjb/tai_from_utc.c | 2 | ||||
-rw-r--r-- | src/libstddjb/utc_from_localtm.c | 6 | ||||
-rw-r--r-- | src/libstddjb/utc_from_ltm64.c | 14 | ||||
-rw-r--r-- | src/libstddjb/utc_from_tai.c | 2 |
11 files changed, 59 insertions, 91 deletions
diff --git a/src/libstddjb/djbtime-internal.h b/src/libstddjb/djbtime-internal.h index f402832..eb4e676 100644 --- a/src/libstddjb/djbtime-internal.h +++ b/src/libstddjb/djbtime-internal.h @@ -3,26 +3,13 @@ #ifndef DJBTIME_INTERNAL_H #define DJBTIME_INTERNAL_H -#include <skalibs/config.h> #include <skalibs/uint64.h> +extern unsigned int const leapsecs_table_len ; +extern uint64 const *const leapsecs_table ; - /* Leap second handling, for UTC <--> TAI conversions */ - -#define LEAPSECS_MAX 39 -#define LEAPSECS_FILE SKALIBS_ETC "/leapsecs.dat" -extern uint64 *leapsecs_here ; - -extern int leapsecs_init_r (char const *, uint64 *) ; -#define leapsecs_init() leapsecs_init_r(LEAPSECS_FILE, leapsecs_here) -extern int leapsecs_add_r (uint64 *, char const *, uint64 *, int) ; -#define leapsecs_add(t, h) leapsecs_add_r(t, LEAPSECS_FILE, leapsecs_here, h) -extern int leapsecs_sub_r (uint64 *, char const *, uint64 *) ; -#define leapsecs_sub(t) leapsecs_sub_r((t), LEAPSECS_FILE, leapsecs_here) - - - /* Run-time test: does the current timezone handle leap seconds ? */ - +extern void leapsecs_add (uint64 *, int) ; +extern int leapsecs_sub (uint64 *) ; extern int skalibs_tzisright (void) ; #endif diff --git a/src/libstddjb/leapsecs_add.c b/src/libstddjb/leapsecs_add.c index c24486b..4b75f7d 100644 --- a/src/libstddjb/leapsecs_add.c +++ b/src/libstddjb/leapsecs_add.c @@ -3,17 +3,14 @@ #include <skalibs/uint64.h> #include "djbtime-internal.h" -int leapsecs_add_r (uint64 *t, char const *file, uint64 *leapsecs, int hit) +void leapsecs_add (uint64 *t, int hit) { uint64 u = *t ; - int n = leapsecs_init_r(file, leapsecs) ; register unsigned int i = 0 ; - if (n < 0) return -1 ; - for (; i < (unsigned int)n ; i++) + for (; i < leapsecs_table_len ; i++) { - if (u < leapsecs[i]) break ; - if (!hit || (leapsecs[i] < u)) ++u ; + if (u < leapsecs_table[i]) break ; + if (!hit || (leapsecs_table[i] < u)) ++u ; } *t = u ; - return n ; } diff --git a/src/libstddjb/leapsecs_here.c b/src/libstddjb/leapsecs_here.c deleted file mode 100644 index 3ecdfd1..0000000 --- a/src/libstddjb/leapsecs_here.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -/* MT-unsafe */ - -#include <skalibs/uint64.h> -#include "djbtime-internal.h" - -static uint64 leapsecs_here_tab[LEAPSECS_MAX+1] ; -uint64 *leapsecs_here = leapsecs_here_tab ; diff --git a/src/libstddjb/leapsecs_init.c b/src/libstddjb/leapsecs_init.c deleted file mode 100644 index 41f9b89..0000000 --- a/src/libstddjb/leapsecs_init.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/uint64.h> -#include <skalibs/djbunix.h> -#include "djbtime-internal.h" - -static unsigned int leapsecs_len (uint64 const *data) -{ - register unsigned int i = 1 ; - while (data[i]) i++ ; - return i ; -} - -static int leapsecs_read (char const *file, uint64 *data) -{ - char s[LEAPSECS_MAX * sizeof(uint64)] ; - register int n = openreadnclose(file, s, LEAPSECS_MAX * sizeof(uint64)) ; - if (n < 0) return -1 ; - if (n % sizeof(uint64)) return (errno = EINVAL, -1) ; - n /= sizeof(uint64) ; - { - register unsigned int i = 0 ; - for (; i < (unsigned int)n ; i++) - uint64_unpack_big(s + i * sizeof(uint64), data + i) ; - } - data[n] = 0 ; - return n ; -} - -int leapsecs_init_r (char const *file, uint64 *data) -{ - return data[0] ? (int)leapsecs_len(data) : leapsecs_read(file, data) ; -} diff --git a/src/libstddjb/leapsecs_sub.c b/src/libstddjb/leapsecs_sub.c index 271f592..f466fac 100644 --- a/src/libstddjb/leapsecs_sub.c +++ b/src/libstddjb/leapsecs_sub.c @@ -3,19 +3,17 @@ #include <skalibs/uint64.h> #include "djbtime-internal.h" -int leapsecs_sub_r (uint64 *t, char const *file, uint64 *leapsecs) +int leapsecs_sub (uint64 *t) { uint64 u = *t ; uint64 d = 0 ; - int n = leapsecs_init_r(file, leapsecs) ; register unsigned int i = 0 ; register int hit = 0 ; - if (n < 0) return -1 ; - for (; i < (unsigned int)n ; i++) + for (; i < leapsecs_table_len ; i++) { - if (u < leapsecs[i]) break ; + if (u < leapsecs_table[i]) break ; ++d ; - if (u == leapsecs[i]) hit = 1 ; + if (u == leapsecs_table[i]) hit = 1 ; } *t = u - d ; return hit ; diff --git a/src/libstddjb/leapsecs_table.c b/src/libstddjb/leapsecs_table.c new file mode 100644 index 0000000..d5a32a9 --- /dev/null +++ b/src/libstddjb/leapsecs_table.c @@ -0,0 +1,39 @@ +/* ISC license. */ + +/* MT-unsafe */ + +#include <skalibs/uint64.h> +#include <skalibs/tai.h> +#include "djbtime-internal.h" + +unsigned int const leapsecs_table_len = 26 ; +static uint64 const leapsecs_table_[26] = +{ + TAI_MAGIC + 78796809, + TAI_MAGIC + 94694410, + TAI_MAGIC + 126230411, + TAI_MAGIC + 157766412, + TAI_MAGIC + 189302413, + TAI_MAGIC + 220924814, + TAI_MAGIC + 252460815, + TAI_MAGIC + 283996816, + TAI_MAGIC + 315532817, + TAI_MAGIC + 362793618, + TAI_MAGIC + 394329619, + TAI_MAGIC + 425865620, + TAI_MAGIC + 489024021, + TAI_MAGIC + 567993622, + TAI_MAGIC + 631152023, + TAI_MAGIC + 662688024, + TAI_MAGIC + 709948825, + TAI_MAGIC + 741484826, + TAI_MAGIC + 773020827, + TAI_MAGIC + 820454428, + TAI_MAGIC + 867715229, + TAI_MAGIC + 915148830, + TAI_MAGIC + 1136073631, + TAI_MAGIC + 1230768032, + TAI_MAGIC + 1341100833, + TAI_MAGIC + 1435708834 +} ; +uint64 const *const leapsecs_table = leapsecs_table_ ; diff --git a/src/libstddjb/ltm64_from_utc.c b/src/libstddjb/ltm64_from_utc.c index 28907c9..7e08eb1 100644 --- a/src/libstddjb/ltm64_from_utc.c +++ b/src/libstddjb/ltm64_from_utc.c @@ -8,7 +8,7 @@ int ltm64_from_utc (uint64 *u) { switch (skalibs_tzisright()) { - case 1 : return leapsecs_add(u, 0) >= 0 ; + case 1 : leapsecs_add(u, 0) ; case 0 : return 1 ; default : return 0 ; } diff --git a/src/libstddjb/tai_from_utc.c b/src/libstddjb/tai_from_utc.c index c5dc62d..3f4d5ec 100644 --- a/src/libstddjb/tai_from_utc.c +++ b/src/libstddjb/tai_from_utc.c @@ -7,6 +7,6 @@ int tai_from_utc (tai_t *t, uint64 u) { - if (leapsecs_add(&u, 0) < 0) return 0 ; + leapsecs_add(&u, 0) ; return tai_u64(t, u + 10) ; } diff --git a/src/libstddjb/utc_from_localtm.c b/src/libstddjb/utc_from_localtm.c index cad1a06..a5886f3 100644 --- a/src/libstddjb/utc_from_localtm.c +++ b/src/libstddjb/utc_from_localtm.c @@ -7,9 +7,7 @@ int utc_from_localtm (uint64 *uu, struct tm const *l) { - uint64 u ; - if (!ltm64_from_localtm(&u, l)) return 0 ; - if (!utc_from_ltm64(&u)) return 0 ; - *uu = u ; + if (!ltm64_from_localtm(uu, l)) return 0 ; + utc_from_ltm64(uu) ; return 1 ; } diff --git a/src/libstddjb/utc_from_ltm64.c b/src/libstddjb/utc_from_ltm64.c index 44aea15..788a539 100644 --- a/src/libstddjb/utc_from_ltm64.c +++ b/src/libstddjb/utc_from_ltm64.c @@ -5,19 +5,11 @@ #include <skalibs/djbtime.h> #include "djbtime-internal.h" -#ifdef SKALIBS_FLAG_CLOCKISTAI - -int utc_from_ltm64 (uint64 *u) -{ - return (leapsecs_sub(u) > 0) ; -} - -#else int utc_from_ltm64 (uint64 *u) { - (void)u ; +#ifdef SKALIBS_FLAG_CLOCKISTAI + leapsecs_sub(u) ; +#endif return 1 ; } - -#endif diff --git a/src/libstddjb/utc_from_tai.c b/src/libstddjb/utc_from_tai.c index 80d2763..1e5e094 100644 --- a/src/libstddjb/utc_from_tai.c +++ b/src/libstddjb/utc_from_tai.c @@ -10,7 +10,7 @@ int utc_from_tai (uint64 *u, tai_t const *t) { uint64 tt = t->x - 10 ; if (t->x < 10U) return (errno = EINVAL, 0) ; - if (leapsecs_sub(&tt) < 0) return 0 ; + leapsecs_sub(&tt) ; *u = tt ; return 1 ; } |