From 1c032ec5855551c44b88f94fc35fa87db4279f0a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 9 Jan 2015 01:00:59 +0000 Subject: tai conversion functions overhaul. API change -> rc for 2.2.0.0 Doc updated. --- src/libstddjb/sysclock_from_localtmn.c | 4 +--- src/libstddjb/sysclock_from_tai.c | 2 ++ src/libstddjb/sysclock_from_tain.c | 10 ++++++++++ src/libstddjb/sysclock_from_utc.c | 2 ++ src/libstddjb/tai_add.c | 4 ++-- src/libstddjb/tai_from_ltm64.c | 2 +- src/libstddjb/tai_from_sysclock.c | 3 +-- src/libstddjb/tai_from_timespec.c | 11 ----------- src/libstddjb/tai_from_timeval.c | 10 ---------- src/libstddjb/tai_from_utc.c | 4 +--- src/libstddjb/tai_now.c | 6 +++--- src/libstddjb/tai_relative_from_timespec.c | 11 ----------- src/libstddjb/tai_relative_from_timeval.c | 10 ---------- src/libstddjb/tai_sub.c | 4 ++-- src/libstddjb/tai_u64.c | 12 ++++++++++++ src/libstddjb/tain_add.c | 15 +++++++++------ src/libstddjb/tain_addsec.c | 13 +++++++------ src/libstddjb/tain_from_ntp.c | 2 +- src/libstddjb/tain_from_sysclock.c | 10 ++++++++++ src/libstddjb/tain_from_timespec.c | 8 +++----- src/libstddjb/tain_from_timespec_sysclock.c | 11 +++++++++++ src/libstddjb/tain_from_timeval.c | 7 +++---- src/libstddjb/tain_from_timeval_sysclock.c | 11 +++++++++++ src/libstddjb/tain_half.c | 6 +++--- src/libstddjb/tain_relative_from_timespec.c | 4 +--- src/libstddjb/tain_relative_from_timeval.c | 3 +-- src/libstddjb/tain_sub.c | 16 +++++++++------- src/libstddjb/tain_sysclock.c | 4 +--- src/libstddjb/tain_ulong.c | 5 +++-- src/libstddjb/time_from_tai.c | 17 +++++++++++++++++ src/libstddjb/time_from_tai_relative.c | 16 ++++++++++++++++ src/libstddjb/time_sysclock_from_tai.c | 20 ++++++++++++++++++++ src/libstddjb/timespec_from_tai.c | 12 ------------ src/libstddjb/timespec_from_tai_relative.c | 19 ------------------- src/libstddjb/timespec_from_tain.c | 9 +++------ src/libstddjb/timespec_from_tain_relative.c | 9 +++------ src/libstddjb/timespec_sysclock_from_tain.c | 11 +++++++++++ src/libstddjb/timeval_from_tai.c | 11 ----------- src/libstddjb/timeval_from_tai_relative.c | 18 ------------------ src/libstddjb/timeval_from_tain.c | 8 +++----- src/libstddjb/timeval_from_tain_relative.c | 8 +++----- src/libstddjb/timeval_sysclock_from_tain.c | 11 +++++++++++ src/libstddjb/utc_from_tai.c | 2 ++ 43 files changed, 199 insertions(+), 182 deletions(-) create mode 100644 src/libstddjb/sysclock_from_tain.c delete mode 100644 src/libstddjb/tai_from_timespec.c delete mode 100644 src/libstddjb/tai_from_timeval.c delete mode 100644 src/libstddjb/tai_relative_from_timespec.c delete mode 100644 src/libstddjb/tai_relative_from_timeval.c create mode 100644 src/libstddjb/tai_u64.c create mode 100644 src/libstddjb/tain_from_sysclock.c create mode 100644 src/libstddjb/tain_from_timespec_sysclock.c create mode 100644 src/libstddjb/tain_from_timeval_sysclock.c create mode 100644 src/libstddjb/time_from_tai.c create mode 100644 src/libstddjb/time_from_tai_relative.c create mode 100644 src/libstddjb/time_sysclock_from_tai.c delete mode 100644 src/libstddjb/timespec_from_tai.c delete mode 100644 src/libstddjb/timespec_from_tai_relative.c create mode 100644 src/libstddjb/timespec_sysclock_from_tain.c delete mode 100644 src/libstddjb/timeval_from_tai.c delete mode 100644 src/libstddjb/timeval_from_tai_relative.c create mode 100644 src/libstddjb/timeval_sysclock_from_tain.c (limited to 'src/libstddjb') diff --git a/src/libstddjb/sysclock_from_localtmn.c b/src/libstddjb/sysclock_from_localtmn.c index 7b227d2..a0ee34b 100644 --- a/src/libstddjb/sysclock_from_localtmn.c +++ b/src/libstddjb/sysclock_from_localtmn.c @@ -5,9 +5,7 @@ int sysclock_from_localtmn (tain_t *a, localtmn_t const *l) { - uint64 u ; - if (!sysclock_from_localtm(&u, &l->tm)) return 0 ; - tai_u64(&a->sec, u) ; + if (!sysclock_from_localtm(&a->sec.x, &l->tm)) return 0 ; a->nano = l->nano ; return 1 ; } diff --git a/src/libstddjb/sysclock_from_tai.c b/src/libstddjb/sysclock_from_tai.c index 3db2640..3814bf2 100644 --- a/src/libstddjb/sysclock_from_tai.c +++ b/src/libstddjb/sysclock_from_tai.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include @@ -7,6 +8,7 @@ int sysclock_from_tai (uint64 *u, tai_t const *t) { + if (t->x < 10U) return (errno = EINVAL, 0) ; *u = t->x - 10U ; return 1 ; } diff --git a/src/libstddjb/sysclock_from_tain.c b/src/libstddjb/sysclock_from_tain.c new file mode 100644 index 0000000..8a2bd12 --- /dev/null +++ b/src/libstddjb/sysclock_from_tain.c @@ -0,0 +1,10 @@ + /* ISC license. */ + +#include + +int sysclock_from_tain (tain_t *u, tain_t const *t) +{ + if (!sysclock_from_tai(&u->sec.x, &t->sec)) return 0 ; + u->nano = t->nano ; + return 1 ; +} diff --git a/src/libstddjb/sysclock_from_utc.c b/src/libstddjb/sysclock_from_utc.c index 25f9205..49228a7 100644 --- a/src/libstddjb/sysclock_from_utc.c +++ b/src/libstddjb/sysclock_from_utc.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -12,6 +13,7 @@ int sysclock_from_utc (uint64 *u) { tai_t t ; if (!tai_from_utc(&t, *u)) return 0 ; + if (t.x < 10) return (errno = EINVAL, 0) ; *u = t.x - 10 ; return 1 ; } diff --git a/src/libstddjb/tai_add.c b/src/libstddjb/tai_add.c index 91af283..ad481ea 100644 --- a/src/libstddjb/tai_add.c +++ b/src/libstddjb/tai_add.c @@ -2,7 +2,7 @@ #include -void tai_add (tai_t *t, tai_t const *u, tai_t const *v) +int tai_add (tai_t *t, tai_t const *u, tai_t const *v) { - tai_u64(t, tai_sec(u) + tai_sec(v)) ; + return tai_u64(t, tai_sec(u) + tai_sec(v)) ; } diff --git a/src/libstddjb/tai_from_ltm64.c b/src/libstddjb/tai_from_ltm64.c index 12a7394..0ecb49a 100644 --- a/src/libstddjb/tai_from_ltm64.c +++ b/src/libstddjb/tai_from_ltm64.c @@ -9,7 +9,7 @@ int tai_from_ltm64 (tai_t *t, uint64 u) { switch (skalibs_tzisright()) { - case 1 : tai_u64(t, u + 10U) ; return 1 ; + case 1 : return tai_u64(t, u + 10U) ; case 0 : return tai_from_utc(t, u) ; default : return 0 ; } diff --git a/src/libstddjb/tai_from_sysclock.c b/src/libstddjb/tai_from_sysclock.c index c2bb546..087f353 100644 --- a/src/libstddjb/tai_from_sysclock.c +++ b/src/libstddjb/tai_from_sysclock.c @@ -7,8 +7,7 @@ int tai_from_sysclock (tai_t *t, uint64 u) { - tai_u64(t, u + 10U) ; - return 1 ; + return tai_u64(t, u + 10U) ; } #else diff --git a/src/libstddjb/tai_from_timespec.c b/src/libstddjb/tai_from_timespec.c deleted file mode 100644 index e9fbe3e..0000000 --- a/src/libstddjb/tai_from_timespec.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int tai_from_timespec (tai_t *t, struct timespec const *ts) -{ - tai_unix(t, ts->tv_sec) ; - return 1 ; -} diff --git a/src/libstddjb/tai_from_timeval.c b/src/libstddjb/tai_from_timeval.c deleted file mode 100644 index 41cf5a1..0000000 --- a/src/libstddjb/tai_from_timeval.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include -#include - -int tai_from_timeval (tai_t *t, struct timeval const *tv) -{ - tai_unix(t, tv->tv_sec) ; - return 1 ; -} diff --git a/src/libstddjb/tai_from_utc.c b/src/libstddjb/tai_from_utc.c index ba9cea9..c5dc62d 100644 --- a/src/libstddjb/tai_from_utc.c +++ b/src/libstddjb/tai_from_utc.c @@ -8,7 +8,5 @@ int tai_from_utc (tai_t *t, uint64 u) { if (leapsecs_add(&u, 0) < 0) return 0 ; - u += 10 ; - t->x = u ; - return 1 ; + return tai_u64(t, u + 10) ; } diff --git a/src/libstddjb/tai_now.c b/src/libstddjb/tai_now.c index a1847ab..aaf388a 100644 --- a/src/libstddjb/tai_now.c +++ b/src/libstddjb/tai_now.c @@ -3,11 +3,11 @@ /* MT-unsafe */ #include -#include #include int tai_now (tai_t *t) { - register uint64 u = TAI_MAGIC + time(0) ; - return tai_from_sysclock(t, u) ; + register time_t u = time(0) ; + if (u == (time_t)-1) return 0 ; + return tai_from_time_sysclock(t, u) ; } diff --git a/src/libstddjb/tai_relative_from_timespec.c b/src/libstddjb/tai_relative_from_timespec.c deleted file mode 100644 index 34bb555..0000000 --- a/src/libstddjb/tai_relative_from_timespec.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int tai_relative_from_timespec (tai_t *t, struct timespec const *ts) -{ - tai_u64(t, ts->tv_sec) ; - return 1 ; -} diff --git a/src/libstddjb/tai_relative_from_timeval.c b/src/libstddjb/tai_relative_from_timeval.c deleted file mode 100644 index f685da7..0000000 --- a/src/libstddjb/tai_relative_from_timeval.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include -#include - -int tai_relative_from_timeval (tai_t *t, struct timeval const *tv) -{ - tai_u64(t, tv->tv_sec) ; - return 1 ; -} diff --git a/src/libstddjb/tai_sub.c b/src/libstddjb/tai_sub.c index d0c879e..e0cda7a 100644 --- a/src/libstddjb/tai_sub.c +++ b/src/libstddjb/tai_sub.c @@ -2,7 +2,7 @@ #include -void tai_sub (tai_t *t, tai_t const *u, tai_t const *v) +int tai_sub (tai_t *t, tai_t const *u, tai_t const *v) { - tai_u64(t, tai_sec(u) - tai_sec(v)) ; + return tai_u64(t, tai_sec(u) - tai_sec(v)) ; } diff --git a/src/libstddjb/tai_u64.c b/src/libstddjb/tai_u64.c new file mode 100644 index 0000000..a26d907 --- /dev/null +++ b/src/libstddjb/tai_u64.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include +#include +#include + +int tai_u64 (tai_t *t, uint64 u) +{ + if (u & ((uint64)1 << 63)) return (errno = EOVERFLOW, 0) ; + t->x = u ; + return 1 ; +} diff --git a/src/libstddjb/tain_add.c b/src/libstddjb/tain_add.c index 6c6a237..aa6e705 100644 --- a/src/libstddjb/tain_add.c +++ b/src/libstddjb/tain_add.c @@ -2,13 +2,16 @@ #include -void tain_add (tain_t *t, tain_t const *u, tain_t const *v) +int tain_add (tain_t *t, tain_t const *u, tain_t const *v) { - tai_add(&t->sec, &u->sec, &v->sec) ; - t->nano = u->nano + v->nano ; - if (t->nano > 999999999U) + tain_t tt = *u ; + if (!tai_add(&tt.sec, &u->sec, &v->sec)) return 0 ; + tt.nano = u->nano + v->nano ; + if (tt.nano > 999999999U) { - t->nano -= 1000000000U ; - tai_u64(&t->sec, tai_sec(&t->sec)+1) ; + if (!tai_u64(&tt.sec, tai_sec(&tt.sec) + 1)) return 0 ; + tt.nano -= 1000000000U ; } + *t = tt ; + return 1 ; } diff --git a/src/libstddjb/tain_addsec.c b/src/libstddjb/tain_addsec.c index f4252a7..524ac20 100644 --- a/src/libstddjb/tain_addsec.c +++ b/src/libstddjb/tain_addsec.c @@ -2,19 +2,20 @@ #include -void tain_addsec (tain_t *b, tain_t const *a, int c) +int tain_addsec (tain_t *b, tain_t const *a, int c) { - b->nano = a->nano ; if (c >= 0) { tai_t t ; - tai_u64(&t, c) ; - tai_add(&b->sec, &a->sec, &t) ; + if (!tai_u64(&t, c)) return 0 ; + if (!tai_add(&b->sec, &a->sec, &t)) return 0 ; } else { tai_t t ; - tai_u64(&t, -c) ; - tai_sub(&b->sec, &a->sec, &t) ; + if (!tai_u64(&t, -c)) return 0 ; + if (!tai_sub(&b->sec, &a->sec, &t)) return 0 ; } + b->nano = a->nano ; + return 1 ; } diff --git a/src/libstddjb/tain_from_ntp.c b/src/libstddjb/tain_from_ntp.c index 6bf7697..5314a38 100644 --- a/src/libstddjb/tain_from_ntp.c +++ b/src/libstddjb/tain_from_ntp.c @@ -6,7 +6,7 @@ int tain_from_ntp (tain_t *a, uint64 u) { - tai_t secs = { u >> 32 } ; + tai_t secs = { .x = u >> 32 } ; if (secs.x <= 0x7FFFFFFFUL) secs.x |= ((uint64)1 << 32) ; secs.x += TAI_MAGIC ; secs.x -= NTP_OFFSET ; diff --git a/src/libstddjb/tain_from_sysclock.c b/src/libstddjb/tain_from_sysclock.c new file mode 100644 index 0000000..468c248 --- /dev/null +++ b/src/libstddjb/tain_from_sysclock.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include + +int tain_from_sysclock (tain_t *a, tain_t const *u) +{ + if (!tai_from_sysclock(&a->sec, u->sec.x)) return 0 ; + a->nano = u->nano ; + return 1 ; +} diff --git a/src/libstddjb/tain_from_timespec.c b/src/libstddjb/tain_from_timespec.c index e862f46..e471b95 100644 --- a/src/libstddjb/tain_from_timespec.c +++ b/src/libstddjb/tain_from_timespec.c @@ -1,13 +1,11 @@ /* ISC license. */ -#include #include -#include #include -int tain_from_timespec (tain_t *a, struct timespec const *ts) +int tain_from_timespec (tain_t *t, struct timespec const *ts) { - if (!tai_from_timespec(tain_secp(a), ts)) return 0 ; - a->nano = ts->tv_nsec ; + if (!tai_from_time(&t->sec, ts->tv_sec)) return 0 ; + t->nano = ts->tv_nsec ; return 1 ; } diff --git a/src/libstddjb/tain_from_timespec_sysclock.c b/src/libstddjb/tain_from_timespec_sysclock.c new file mode 100644 index 0000000..b79cda8 --- /dev/null +++ b/src/libstddjb/tain_from_timespec_sysclock.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include +#include + +int tain_from_timespec_sysclock (tain_t *t, struct timespec const *ts) +{ + if (!tai_from_time_sysclock(&t->sec, ts->tv_sec)) return 0 ; + t->nano = ts->tv_nsec ; + return 1 ; +} diff --git a/src/libstddjb/tain_from_timeval.c b/src/libstddjb/tain_from_timeval.c index 9c74d13..0536070 100644 --- a/src/libstddjb/tain_from_timeval.c +++ b/src/libstddjb/tain_from_timeval.c @@ -1,12 +1,11 @@ /* ISC license. */ #include -#include #include -int tain_from_timeval (tain_t *a, struct timeval const *tv) +int tain_from_timeval (tain_t *t, struct timeval const *tv) { - if (!tai_from_timeval(tain_secp(a), tv)) return 0 ; - a->nano = 1000 * tv->tv_usec ; + if (!tai_from_time(&t->sec, tv->tv_sec)) return 0 ; + t->nano = 1000 * tv->tv_usec ; return 1 ; } diff --git a/src/libstddjb/tain_from_timeval_sysclock.c b/src/libstddjb/tain_from_timeval_sysclock.c new file mode 100644 index 0000000..625c4cd --- /dev/null +++ b/src/libstddjb/tain_from_timeval_sysclock.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include +#include + +int tain_from_timeval_sysclock (tain_t *t, struct timeval const *tv) +{ + if (!tai_from_time_sysclock(&t->sec, tv->tv_sec)) return 0 ; + t->nano = 1000 * tv->tv_usec ; + return 1 ; +} diff --git a/src/libstddjb/tain_half.c b/src/libstddjb/tain_half.c index a95072e..4b8f404 100644 --- a/src/libstddjb/tain_half.c +++ b/src/libstddjb/tain_half.c @@ -4,7 +4,7 @@ void tain_half (tain_t *t, tain_t const *u) { - t->nano = u->nano>>1 ; - if (tai_sec(&u->sec) & 1) t->nano += 500000000U ; - tai_u64(&t->sec, tai_sec(&u->sec)>>1) ; + t->nano = u->nano >> 1 ; + if (u->sec.x & 1) t->nano += 500000000U ; + t->sec.x = u->sec.x >> 1 ; } diff --git a/src/libstddjb/tain_relative_from_timespec.c b/src/libstddjb/tain_relative_from_timespec.c index e25793e..5f492ff 100644 --- a/src/libstddjb/tain_relative_from_timespec.c +++ b/src/libstddjb/tain_relative_from_timespec.c @@ -1,13 +1,11 @@ /* ISC license. */ -#include #include -#include #include int tain_relative_from_timespec (tain_t *a, struct timespec const *ts) { - if (!tai_relative_from_timespec(tain_secp(a), ts)) return 0 ; + tai_relative_from_time(&a->sec, ts->tv_sec) ; a->nano = ts->tv_nsec ; return 1 ; } diff --git a/src/libstddjb/tain_relative_from_timeval.c b/src/libstddjb/tain_relative_from_timeval.c index 83aa1c3..eafb57a 100644 --- a/src/libstddjb/tain_relative_from_timeval.c +++ b/src/libstddjb/tain_relative_from_timeval.c @@ -1,12 +1,11 @@ /* ISC license. */ #include -#include #include int tain_relative_from_timeval (tain_t *a, struct timeval const *tv) { - if (!tai_relative_from_timeval(tain_secp(a), tv)) return 0 ; + tai_relative_from_time(&a->sec, tv->tv_sec) ; a->nano = 1000 * tv->tv_usec ; return 1 ; } diff --git a/src/libstddjb/tain_sub.c b/src/libstddjb/tain_sub.c index f7dd4eb..2921aa6 100644 --- a/src/libstddjb/tain_sub.c +++ b/src/libstddjb/tain_sub.c @@ -2,14 +2,16 @@ #include -void tain_sub (tain_t *t, tain_t const *u, tain_t const *v) +int tain_sub (tain_t *t, tain_t const *u, tain_t const *v) { - tain_t uu = *u ; - tai_sub(&t->sec, &uu.sec, &v->sec) ; - t->nano = uu.nano - v->nano ; - if (t->nano > uu.nano) + tain_t tt = *u ; + if (!tai_sub(&tt.sec, &u->sec, &v->sec)) return 0 ; + tt.nano = u->nano - v->nano ; + if (tt.nano > u->nano) { - t->nano += 1000000000U ; - tai_u64(&t->sec, tai_sec(&t->sec)-1) ; + if (!tai_u64(&tt.sec, tai_sec(&tt.sec) - 1)) return 0 ; + tt.nano += 1000000000U ; } + *t = tt ; + return 1 ; } diff --git a/src/libstddjb/tain_sysclock.c b/src/libstddjb/tain_sysclock.c index 7f54db6..3b98eb1 100644 --- a/src/libstddjb/tain_sysclock.c +++ b/src/libstddjb/tain_sysclock.c @@ -6,7 +6,5 @@ int tain_sysclock (tain_t *a) { tain_t aa ; if (!sysclock_get(&aa)) return 0 ; - if (!tai_from_sysclock(&a->sec, aa.sec.x)) return 0 ; - a->nano = aa.nano ; - return 1 ; + return tain_from_sysclock(a, &aa) ; } diff --git a/src/libstddjb/tain_ulong.c b/src/libstddjb/tain_ulong.c index 2ba730a..8eb890b 100644 --- a/src/libstddjb/tain_ulong.c +++ b/src/libstddjb/tain_ulong.c @@ -2,8 +2,9 @@ #include -void tain_ulong (tain_t *t, unsigned long s) +int tain_ulong (tain_t *t, unsigned long s) { - tai_u64(&t->sec, s) ; + if (!tai_u64(&t->sec, s)) return 0 ; t->nano = 0 ; + return 1 ; } diff --git a/src/libstddjb/time_from_tai.c b/src/libstddjb/time_from_tai.c new file mode 100644 index 0000000..e03b8c5 --- /dev/null +++ b/src/libstddjb/time_from_tai.c @@ -0,0 +1,17 @@ + /* ISC license. */ + +#include +#include +#include +#include + +int time_from_tai (time_t *u, tai_t const *t) +{ + register uint64 uu = t->x - TAI_MAGIC ; +#if SKALIBS_SIZEOFTIME < 8 + if ((uu >> 32) && (uu >> 32) != 0xffffffffUL) + return (errno = EOVERFLOW, 0) ; +#endif + *u = (time_t)uu ; + return 1 ; +} diff --git a/src/libstddjb/time_from_tai_relative.c b/src/libstddjb/time_from_tai_relative.c new file mode 100644 index 0000000..f5233fe --- /dev/null +++ b/src/libstddjb/time_from_tai_relative.c @@ -0,0 +1,16 @@ + /* ISC license. */ + +#include +#include +#include +#include + +int time_from_tai_relative (time_t *u, tai_t const *t) +{ +#if SKALIBS_SIZEOFTIME < 8 + if ((t->x >> 32) && (t->x >> 32) != 0xffffffffUL) + return (errno = EOVERFLOW, 0) ; +#endif + *u = (time_t)t->x ; + return 1 ; +} diff --git a/src/libstddjb/time_sysclock_from_tai.c b/src/libstddjb/time_sysclock_from_tai.c new file mode 100644 index 0000000..c16dbe2 --- /dev/null +++ b/src/libstddjb/time_sysclock_from_tai.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +int time_sysclock_from_tai (time_t *u, tai_t const *t) +{ + uint64 uu ; + if (!sysclock_from_tai(&uu, t)) return 0 ; + uu -= TAI_MAGIC ; +#if SKALIBS_SIZEOFTIME < 8 + if ((uu >> 32) && (uu >> 32) != 0xffffffffUL) + return (errno = EOVERFLOW, 0) ; +#endif + *u = (time_t)uu ; + return 1 ; +} diff --git a/src/libstddjb/timespec_from_tai.c b/src/libstddjb/timespec_from_tai.c deleted file mode 100644 index 7bb84d4..0000000 --- a/src/libstddjb/timespec_from_tai.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -int timespec_from_tai (struct timespec *ts, tai_t const *t) -{ - tai_t trel ; - tai_u64(&trel, tai_sec(t) - TAI_MAGIC) ; - return timespec_from_tai_relative(ts, &trel) ; -} diff --git a/src/libstddjb/timespec_from_tai_relative.c b/src/libstddjb/timespec_from_tai_relative.c deleted file mode 100644 index 42f2e95..0000000 --- a/src/libstddjb/timespec_from_tai_relative.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include - -int timespec_from_tai_relative (struct timespec *ts, tai_t const *t) -{ - if (tai_sec(t) >= (uint64)1 << 63) return (errno = EINVAL, 0) ; -#if SKALIBS_SIZEOFTIME < 8 - if (tai_sec(t) > 0xffffffffU) return (errno = ERANGE, 0) ; -#endif - ts->tv_sec = (time_t)tai_sec(t) ; - ts->tv_nsec = 0 ; - return 1 ; -} diff --git a/src/libstddjb/timespec_from_tain.c b/src/libstddjb/timespec_from_tain.c index 5eb6e30..cd63547 100644 --- a/src/libstddjb/timespec_from_tain.c +++ b/src/libstddjb/timespec_from_tain.c @@ -1,14 +1,11 @@ /* ISC license. */ -#include #include #include -int timespec_from_tain (struct timespec *ts, tain_t const *a) +int timespec_from_tain (struct timespec *ts, tain_t const *t) { - struct timespec tmp ; - if (!timespec_from_tai(&tmp, tain_secp(a))) return 0 ; - ts->tv_sec = tmp.tv_sec ; - ts->tv_nsec = a->nano ; + if (!time_from_tai(&ts->tv_sec, &t->sec)) return 0 ; + ts->tv_nsec = t->nano ; return 1 ; } diff --git a/src/libstddjb/timespec_from_tain_relative.c b/src/libstddjb/timespec_from_tain_relative.c index 32e7993..8ef34e8 100644 --- a/src/libstddjb/timespec_from_tain_relative.c +++ b/src/libstddjb/timespec_from_tain_relative.c @@ -1,14 +1,11 @@ /* ISC license. */ -#include #include #include -int timespec_from_tain_relative (struct timespec *ts, tain_t const *a) +int timespec_from_tain_relative (struct timespec *ts, tain_t const *t) { - struct timespec tmp ; - if (!timespec_from_tai_relative(&tmp, tain_secp(a))) return 0 ; - ts->tv_sec = tmp.tv_sec ; - ts->tv_nsec = a->nano ; + if (!time_from_tai_relative(&ts->tv_sec, &t->sec)) return 0 ; + ts->tv_nsec = t->nano ; return 1 ; } diff --git a/src/libstddjb/timespec_sysclock_from_tain.c b/src/libstddjb/timespec_sysclock_from_tain.c new file mode 100644 index 0000000..5544511 --- /dev/null +++ b/src/libstddjb/timespec_sysclock_from_tain.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include +#include + +int timespec_sysclock_from_tain (struct timespec *ts, tain_t const *t) +{ + if (!time_sysclock_from_tai(&ts->tv_sec, &t->sec)) return 0 ; + ts->tv_nsec = t->nano ; + return 1 ; +} diff --git a/src/libstddjb/timeval_from_tai.c b/src/libstddjb/timeval_from_tai.c deleted file mode 100644 index d0c4777..0000000 --- a/src/libstddjb/timeval_from_tai.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include -#include - -int timeval_from_tai (struct timeval *tv, tai_t const *t) -{ - tai_t trel ; - tai_u64(&trel, tai_sec(t) - TAI_MAGIC) ; - return timeval_from_tai_relative(tv, &trel) ; -} diff --git a/src/libstddjb/timeval_from_tai_relative.c b/src/libstddjb/timeval_from_tai_relative.c deleted file mode 100644 index 94bd3f7..0000000 --- a/src/libstddjb/timeval_from_tai_relative.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include - -int timeval_from_tai_relative (struct timeval *tv, tai_t const *t) -{ - if (tai_sec(t) >= (uint64)1 << 63) return (errno = EINVAL, 0) ; -#if SKALIBS_SIZEOFTIME < 8 - if (tai_sec(t) > 0xffffffffU) return (errno = ERANGE, 0) ; -#endif - tv->tv_sec = (time_t)tai_sec(t) ; - tv->tv_usec = 0 ; - return 1 ; -} diff --git a/src/libstddjb/timeval_from_tain.c b/src/libstddjb/timeval_from_tain.c index c780af7..2b4d577 100644 --- a/src/libstddjb/timeval_from_tain.c +++ b/src/libstddjb/timeval_from_tain.c @@ -3,11 +3,9 @@ #include #include -int timeval_from_tain (struct timeval *tv, tain_t const *a) +int timeval_from_tain (struct timeval *tv, tain_t const *t) { - struct timeval tmp ; - if (!timeval_from_tai(&tmp, tain_secp(a))) return 0 ; - tv->tv_sec = tmp.tv_sec ; - tv->tv_usec = a->nano / 1000 ; + if (!time_from_tai(&tv->tv_sec, &t->sec)) return 0 ; + tv->tv_usec = (t->nano + 500) / 1000 ; return 1 ; } diff --git a/src/libstddjb/timeval_from_tain_relative.c b/src/libstddjb/timeval_from_tain_relative.c index 624293c..de775fd 100644 --- a/src/libstddjb/timeval_from_tain_relative.c +++ b/src/libstddjb/timeval_from_tain_relative.c @@ -3,11 +3,9 @@ #include #include -int timeval_from_tain_relative (struct timeval *tv, tain_t const *a) +int timeval_from_tain_relative (struct timeval *tv, tain_t const *t) { - struct timeval tmp ; - if (!timeval_from_tai_relative(&tmp, tain_secp(a))) return 0 ; - tv->tv_sec = tmp.tv_sec ; - tv->tv_usec = a->nano / 1000 ; + if (!time_from_tai_relative(&tv->tv_sec, &t->sec)) return 0 ; + tv->tv_usec = (t->nano + 500) / 1000 ; return 1 ; } diff --git a/src/libstddjb/timeval_sysclock_from_tain.c b/src/libstddjb/timeval_sysclock_from_tain.c new file mode 100644 index 0000000..c41b133 --- /dev/null +++ b/src/libstddjb/timeval_sysclock_from_tain.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include +#include + +int timeval_sysclock_from_tain (struct timeval *tv, tain_t const *t) +{ + if (!time_sysclock_from_tai(&tv->tv_sec, &t->sec)) return 0 ; + tv->tv_usec = (t->nano + 500) / 1000 ; + return 1 ; +} diff --git a/src/libstddjb/utc_from_tai.c b/src/libstddjb/utc_from_tai.c index f4d247e..80d2763 100644 --- a/src/libstddjb/utc_from_tai.c +++ b/src/libstddjb/utc_from_tai.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -8,6 +9,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 ; *u = tt ; return 1 ; -- cgit v1.2.3