diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libstddjb/sysclock_get.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libstddjb/sysclock_get.c')
-rw-r--r-- | src/libstddjb/sysclock_get.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 <skalibs/config.h> +#include <skalibs/sysdeps.h> +#include <skalibs/tai.h> + +#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 <time.h> + +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 <sys/time.h> + +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 |