diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-02 10:15:29 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-02 10:15:29 +0000 |
commit | 4fd65aec913a1b99e8d748a7a82c150b8f7ee510 (patch) | |
tree | d34ac61e9cca0729320c0854c87a3163efd52836 /src | |
parent | 131a18f68dc73f208bb76a944fc6d42c86cfad3b (diff) | |
download | skalibs-4fd65aec913a1b99e8d748a7a82c150b8f7ee510.tar.xz |
Remove the --enable-right-tz configure option.
Make it a run-time autodetection instead.
Update doc.
Thanks to Paul Jarc for the suggestion.
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/djbtime.h | 2 | ||||
-rw-r--r-- | src/libstddjb/djbtime-internal.h | 6 | ||||
-rw-r--r-- | src/libstddjb/ltm64_from_tai.c | 21 | ||||
-rw-r--r-- | src/libstddjb/ltm64_from_utc.c | 20 | ||||
-rw-r--r-- | src/libstddjb/skalibs_tzisright.c | 17 | ||||
-rw-r--r-- | src/libstddjb/tai_from_ltm64.c | 21 |
6 files changed, 43 insertions, 44 deletions
diff --git a/src/include/skalibs/djbtime.h b/src/include/skalibs/djbtime.h index 8aace55..7e60cd4 100644 --- a/src/include/skalibs/djbtime.h +++ b/src/include/skalibs/djbtime.h @@ -27,7 +27,7 @@ extern int tain_from_ntp (tain_t *, uint64) ; /* localtime handling - replaces caltimedate functions */ -/* ltm64 can be either TAI-10 or UTC depending on --enable-right-tz */ +/* ltm64 can be either TAI-10 or UTC depending on the current timezone */ /* normally ltm64 is the same as sysclock, but we allow it to be different */ /* for instance for musl TAI-10 systems */ diff --git a/src/libstddjb/djbtime-internal.h b/src/libstddjb/djbtime-internal.h index 26ffc81..819b88a 100644 --- a/src/libstddjb/djbtime-internal.h +++ b/src/libstddjb/djbtime-internal.h @@ -6,7 +6,7 @@ #include <skalibs/uint64.h> -/* Leap second handling, for UTC <--> TAI conversions */ + /* Leap second handling, for UTC <--> TAI conversions */ #define LEAPSECS_MAX 39 #define LEAPSECS_FILE SKALIBS_ETC "/leapsecs.dat" @@ -20,4 +20,8 @@ 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 int skalibs_tzisright (void) ; + #endif diff --git a/src/libstddjb/ltm64_from_tai.c b/src/libstddjb/ltm64_from_tai.c index c0650c5..9161a79 100644 --- a/src/libstddjb/ltm64_from_tai.c +++ b/src/libstddjb/ltm64_from_tai.c @@ -1,23 +1,16 @@ /* ISC license. */ -#include <skalibs/config.h> #include <skalibs/uint64.h> #include <skalibs/tai.h> #include <skalibs/djbtime.h> - -#ifdef SKALIBS_FLAG_TZISRIGHT +#include "djbtime-internal.h" int ltm64_from_tai (uint64 *u, tai_t const *t) { - *u = t->x - 10U ; - return 1 ; + switch (skalibs_tzisright()) + { + case 1 : *u = t->x - 10U ; return 1 ; + case 0 : return utc_from_tai(u, t) ; + default : return 0 ; + } } - -#else - -int ltm64_from_tai (uint64 *u, tai_t const *t) -{ - return utc_from_tai(u, t) ; -} - -#endif diff --git a/src/libstddjb/ltm64_from_utc.c b/src/libstddjb/ltm64_from_utc.c index 8d66813..28907c9 100644 --- a/src/libstddjb/ltm64_from_utc.c +++ b/src/libstddjb/ltm64_from_utc.c @@ -1,23 +1,15 @@ /* ISC license. */ -#include <skalibs/config.h> #include <skalibs/uint64.h> #include <skalibs/djbtime.h> #include "djbtime-internal.h" -#ifdef SKALIBS_FLAG_TZISRIGHT - int ltm64_from_utc (uint64 *u) { - return (leapsecs_add(u, 0) >= 0) ; + switch (skalibs_tzisright()) + { + case 1 : return leapsecs_add(u, 0) >= 0 ; + case 0 : return 1 ; + default : return 0 ; + } } - -#else - -int ltm64_from_utc (uint64 *u) -{ - (void)u ; - return 1 ; -} - -#endif diff --git a/src/libstddjb/skalibs_tzisright.c b/src/libstddjb/skalibs_tzisright.c new file mode 100644 index 0000000..f8414a6 --- /dev/null +++ b/src/libstddjb/skalibs_tzisright.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include <sys/types.h> +#include <time.h> +#include "djbtime-internal.h" + +int skalibs_tzisright () +{ + static int tzisright = -1 ; + if (tzisright < 0) + { + struct tm tm ; + time_t t = 78796800 ; + if (localtime_r(&t, &tm)) tzisright = tm.tm_sec == 60 ; + } + return tzisright ; +} diff --git a/src/libstddjb/tai_from_ltm64.c b/src/libstddjb/tai_from_ltm64.c index 2538c00..12a7394 100644 --- a/src/libstddjb/tai_from_ltm64.c +++ b/src/libstddjb/tai_from_ltm64.c @@ -1,23 +1,16 @@ /* ISC license. */ -#include <skalibs/config.h> #include <skalibs/uint64.h> #include <skalibs/tai.h> #include <skalibs/djbtime.h> - -#ifdef SKALIBS_FLAG_TZISRIGHT +#include "djbtime-internal.h" int tai_from_ltm64 (tai_t *t, uint64 u) { - tai_u64(t, u + 10U) ; - return 1 ; + switch (skalibs_tzisright()) + { + case 1 : tai_u64(t, u + 10U) ; return 1 ; + case 0 : return tai_from_utc(t, u) ; + default : return 0 ; + } } - -#else - -int tai_from_ltm64 (tai_t *t, uint64 u) -{ - return tai_from_utc(t, u) ; -} - -#endif |