diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2011-08-10 11:31:18 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2011-08-10 11:31:18 +0000 |
commit | bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81 (patch) | |
tree | 88bf10a027d3103814943c3bd80bc630457d46d5 /Src/Modules/datetime.c | |
parent | 92ee9324a96cd503c2ebc82cf84c03ddb08bf434 (diff) | |
download | zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.tar.gz zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.tar.xz zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.zip |
29663: add $EPOCHREALTIME to zsh/datetime
Diffstat (limited to 'Src/Modules/datetime.c')
-rw-r--r-- | Src/Modules/datetime.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index 45818b968..1f2b7e81c 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -151,6 +151,28 @@ getcurrentsecs(UNUSED(Param pm)) return (zlong) time(NULL); } +static double +getcurrentrealtime(UNUSED(Param pm)) +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec now; + + if (clock_gettime(CLOCK_REALTIME, &now) < 0) { + zwarn("EPOCHREALTIME: unable to retrieve time: %e", errno); + return (double)0.0; + } + + return (double)now.tv_sec + (double)now.tv_nsec * 1e-9; +#else + struct timeval now; + struct timezone dummy_tz; + + gettimeofday(&now, &dummy_tz); + + return (double)now.tv_sec + (double)now.tv_usec * 1e-6; +#endif +} + static struct builtin bintab[] = { BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, "qrs:", NULL), }; @@ -158,9 +180,14 @@ static struct builtin bintab[] = { static const struct gsu_integer epochseconds_gsu = { getcurrentsecs, NULL, stdunsetfn }; +static const struct gsu_float epochrealtime_gsu = +{ getcurrentrealtime, NULL, stdunsetfn }; + static struct paramdef patab[] = { SPECIALPMDEF("EPOCHSECONDS", PM_INTEGER|PM_READONLY, &epochseconds_gsu, NULL, NULL), + SPECIALPMDEF("EPOCHREALTIME", PM_FFLOAT|PM_READONLY, + &epochrealtime_gsu, NULL, NULL) }; static struct features module_features = { |