diff options
author | Cedric Ware <cedric.ware__bml@normalesup.org> | 2020-04-20 12:10:01 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2020-04-20 12:10:01 -0500 |
commit | 25c9b61a6663f90bfb22fa73c1a7aa4fb9dee4ae (patch) | |
tree | 120e8f1e11ab3791b6fbe1d6302dda275d09c2ac /Src/compat.c | |
parent | f179dbf72a4f482c1ad513b7c58cd7f96c7cf7f3 (diff) | |
download | zsh-25c9b61a6663f90bfb22fa73c1a7aa4fb9dee4ae.tar.gz zsh-25c9b61a6663f90bfb22fa73c1a7aa4fb9dee4ae.tar.xz zsh-25c9b61a6663f90bfb22fa73c1a7aa4fb9dee4ae.zip |
45708: zsh/system: Enable sub-second timeout in zsystem flock
Diffstat (limited to 'Src/compat.c')
-rw-r--r-- | Src/compat.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Src/compat.c b/Src/compat.c index 74e426fba..817bb4aaf 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -126,6 +126,32 @@ zgettime(struct timespec *ts) return ret; } +/* Likewise with CLOCK_MONOTONIC if available. */ + +/**/ +mod_export int +zgettime_monotonic_if_available(struct timespec *ts) +{ + int ret = -1; + +#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) + struct timespec dts; + if (clock_gettime(CLOCK_MONOTONIC, &dts) < 0) { + zwarn("unable to retrieve CLOCK_MONOTONIC time: %e", errno); + ret--; + } else { + ret++; + ts->tv_sec = (time_t) dts.tv_sec; + ts->tv_nsec = (long) dts.tv_nsec; + } +#endif + + if (ret) { + ret = zgettime(ts); + } + return ret; +} + /* compute the difference between two calendar times */ |