about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStephane Chazelas <stephane.chazelas@gmail.com>2016-02-24 17:09:04 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2016-02-26 11:12:32 +0000
commitf7d5ff31ce8d354dd69de619e703b9c0e49f0977 (patch)
tree532d4bf25a7cb35662995eeaa3bf3d3f4cb27e00
parentc55d8551718bcf2fc7661c31c13e934060a5f1a7 (diff)
downloadzsh-f7d5ff31ce8d354dd69de619e703b9c0e49f0977.tar.gz
zsh-f7d5ff31ce8d354dd69de619e703b9c0e49f0977.tar.xz
zsh-f7d5ff31ce8d354dd69de619e703b9c0e49f0977.zip
38020: fix problems with $SECONDS.
Fractions of a second were not handled correctly.
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c6
2 files changed, 8 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e3162f21..8498c5954 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-26  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* Stephane: 38020: fix problems with fractions of a second in
+	$SECONDS.
+
 2016-02-25  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 38024: Src/signals.c, Test/C03traps.ztst: improve 37999 to
diff --git a/Src/params.c b/Src/params.c
index 8bd8a8eee..7c5f79fff 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3804,8 +3804,8 @@ intsecondsgetfn(UNUSED(Param pm))
 
     gettimeofday(&now, &dummy_tz);
 
-    return (zlong)(now.tv_sec - shtimer.tv_sec) +
-	(zlong)(now.tv_usec - shtimer.tv_usec) / (zlong)1000000;
+    return (zlong)(now.tv_sec - shtimer.tv_sec -
+		  (now.tv_usec < shtimer.tv_usec ? 1 : 0));
 }
 
 /* Function to set value of special parameter `SECONDS' */
@@ -3823,7 +3823,7 @@ intsecondssetfn(UNUSED(Param pm), zlong x)
     shtimer.tv_sec = diff;
     if ((zlong)shtimer.tv_sec != diff)
 	zwarn("SECONDS truncated on assignment");
-    shtimer.tv_usec = 0;
+    shtimer.tv_usec = now.tv_usec;
 }
 
 /**/