From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/sysclock_get.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/libstddjb/sysclock_get.c (limited to 'src/libstddjb/sysclock_get.c') diff --git a/src/libstddjb/sysclock_get.c b/src/libstddjb/sysclock_get.c new file mode 100644 index 0000000..3d14f96 --- /dev/null +++ b/src/libstddjb/sysclock_get.c @@ -0,0 +1,42 @@ +/* ISC license. */ + +#include +#include +#include + +#ifdef SKALIBS_FLAG_USERT +# ifndef SKALIBS_HASCLOCKRT +# undef SKALIBS_FLAG_USERT +# warning "SKALIBS_FLAG_USERT set but SKALIBS_HASCLOCKRT not found. Clearing SKALIBS_FLAG_USERT." +# endif +#endif + +#ifdef SKALIBS_FLAG_USERT + +#include + +int sysclock_get (tain_t *a) +{ + tain_t aa ; + struct timespec now ; + if (clock_gettime(CLOCK_REALTIME, &now) < 0) return 0 ; + if (!tain_from_timespec(&aa, &now)) return 0 ; + tain_add(a, &aa, &tain_nano500) ; + return 1 ; +} + +#else + +#include + +int sysclock_get (tain_t *a) +{ + tain_t aa ; + struct timeval now ; + if (gettimeofday(&now, 0) < 0) return 0 ; + if (!tain_from_timeval(&aa, &now)) return 0 ; + tain_add(a, &aa, &tain_nano500) ; + return 1 ; +} + +#endif -- cgit v1.2.3