diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2018-08-27 13:31:04 +0200 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2018-08-27 13:31:04 +0200 |
commit | 719a715614f2182a76b30ad27a327d70a86f34f1 (patch) | |
tree | a437eb29da8035bf7c2e30506c08fe6f15719871 /Src/compat.c | |
parent | 7da8d19c224860ae4d6aa3f077fca7f734f20d88 (diff) | |
parent | ef61918398517473b9b594690a3be375f607cebe (diff) | |
download | zsh-719a715614f2182a76b30ad27a327d70a86f34f1.tar.gz zsh-719a715614f2182a76b30ad27a327d70a86f34f1.zip |
Merge tag 'zsh-5.5.1-test-2' into debian
Test release: 5.5.1-test-2.
Diffstat (limited to 'Src/compat.c')
-rw-r--r-- | Src/compat.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Src/compat.c b/Src/compat.c index a130d9264..7b5c4411c 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -94,6 +94,39 @@ gettimeofday(struct timeval *tv, struct timezone *tz) #endif +/* Provide clock time with nanoseconds */ + +/**/ +mod_export int +zgettime(struct timespec *ts) +{ + int ret = -1; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec dts; + if (clock_gettime(CLOCK_REALTIME, &dts) < 0) { + zwarn("unable to retrieve time: %e", errno); + ret--; + } else { + ret++; + ts->tv_sec = (time_t) dts.tv_sec; + ts->tv_nsec = (long) dts.tv_nsec; + } +#endif + + if (ret) { + struct timeval dtv; + struct timezone dtz; + gettimeofday(&dtv, &dtz); + ret++; + ts->tv_sec = (time_t) dtv.tv_sec; + ts->tv_nsec = (long) dtv.tv_usec * 1000; + } + + return ret; +} + + /* compute the difference between two calendar times */ /**/ |