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 | |
parent | 92ee9324a96cd503c2ebc82cf84c03ddb08bf434 (diff) | |
download | zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.tar.gz zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.tar.xz zsh-bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81.zip |
29663: add $EPOCHREALTIME to zsh/datetime
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | Doc/Zsh/mod_datetime.yo | 10 | ||||
-rw-r--r-- | Src/Modules/datetime.c | 27 | ||||
-rw-r--r-- | Src/module.c | 5 | ||||
-rw-r--r-- | configure.ac | 4 |
5 files changed, 56 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index 078971581..658dca388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-08-10 Peter Stephenson <pws@csr.com> + + * 29663: configure.ac, Src/module.c, Src/Modules/datetime.c, + Doc/Zsh/mod_datetime.yo: add $EPOCHREALTIME for time in + double precision floating point. + +2011-08-04 Peter Stephenson <pws@csr.com> + + * 29643: Src/signals.c, Src/utils.c, Src/zle_main.c: set + incompfunc to zero when executing hook or trap function. + 2011-08-09 Peter Stephenson <p.w.stephenson@ntlworld.com> * 29661: Doc/Zsh/redirect.yo: Improve the documentation for @@ -15213,5 +15224,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5417 $ +* $Revision: 1.5418 $ ***************************************************** diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo index 145d4a181..514c43037 100644 --- a/Doc/Zsh/mod_datetime.yo +++ b/Doc/Zsh/mod_datetime.yo @@ -30,9 +30,17 @@ in seconds if tt(-r) is given) to var(scalar) instead of printing it. ) enditem() -The tt(zsh/datetime) module makes available one parameter: +The tt(zsh/datetime) module makes available several parameters: startitem() +vindex(EPOCHREALTIME) +item(tt(EPOCHREALTIME))( +A floating point value representing the number of seconds since +the epoch. The notional accuracy is to nanoseconds if the +tt(clock_gettime) call is available and to microseconds otherwise, +but in practice the range of double precision floating point and +shell scheduling latencies may be significant effects. +) vindex(EPOCHSECONDS) item(tt(EPOCHSECONDS))( An integer value representing the number of seconds since the 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 = { diff --git a/Src/module.c b/Src/module.c index 219bdfa8e..a5a6029b4 100644 --- a/Src/module.c +++ b/Src/module.c @@ -1081,6 +1081,11 @@ addparamdef(Paramdef d) pm->gsu.i = d->gsu ? (GsuInteger)d->gsu : &varinteger_gsu; break; + case PM_FFLOAT: + case PM_EFLOAT: + pm->gsu.f = d->gsu; + break; + case PM_ARRAY: pm->gsu.a = d->gsu ? (GsuArray)d->gsu : &vararray_gsu; break; diff --git a/configure.ac b/configure.ac index 1ce815ca5..54999b164 100644 --- a/configure.ac +++ b/configure.ac @@ -693,6 +693,8 @@ AC_CHECK_LIB(c, printf, [LIBS="$LIBS -lc"]) AC_CHECK_LIB(m, pow) +AC_CHECK_LIB(rt, clock_gettime) + dnl Various features of ncurses depend on having the right header dnl (the system's own curses.h may well not be good enough). dnl So don't search for ncurses unless we found the header. @@ -1170,7 +1172,7 @@ dnl need to integrate this function dnl AC_FUNC_STRFTIME AC_CHECK_FUNCS(strftime strptime mktime timelocal \ - difftime gettimeofday \ + difftime gettimeofday clock_gettime \ select poll \ readlink faccessx fchdir ftruncate \ fstat lstat lchown fchown fchmod \ |