On 06/10/2014 03:43 AM, Eli Zaretskii wrote:
>> Date: Tue, 10 Jun 2014 00:42:22 +0100
>> From: Pádraig Brady <p...@draigbrady.com>
>> CC: bug-gnulib@gnu.org
>>
>>>   . The value is constant: every call to 'times' within the same
>>>     process returns the same value.  Callers generally expect the
>>>     value to change, since Posix says the value is the elapsed time
>>>     since some arbitrary point in time, and that point doesn't change
>>>     for function calls in the same process.  For example, Guile's test
>>>     suite includes a test that calls 'times', sleeps for a few
>>>     seconds, then calls 'times' again, and expects the return value to
>>>     change by approximately the number of seconds it slept.
>>
>> This seems correct. I.E. times() should count up.
>> I'll merge this but with s/change by/change according to/ in the line above.

Pushed the attached, thanks.

Pádraig.

>From b0d4fe9539b3c4651bfa6a34af03fe93f69cc72a Mon Sep 17 00:00:00 2001
From: Eli Zaretskii <e...@gnu.org>
Date: Tue, 10 Jun 2014 21:22:16 +0100
Subject: [PATCH] times: fix to return non constant value on MS-Windows

The existing implementation of times() for MS-Windows uses the process
creation time returned by the GetProcessTimes API to construct the
value that the function should return, which has two problems:

  The value is constant: every call to 'times' within the same
  process returns the same value.  Callers generally expect the
  value to change, since Posix says the value is the elapsed time
  since some arbitrary point in time, and that point doesn't change
  for function calls in the same process.  For example, Guile's test
  suite includes a test that calls 'times', sleeps for a few
  seconds, then calls 'times' again, and expects the return value to
  change according to approximately the number of seconds it slept.

  The value overflows the clock_t data type (which is 32 bits wide),
  because its point of origin is Jan 1, 1601.  This is unnecessary,
  since the point of origin can change from process to process.

* lib/times.c (times): Don't use the process creation time,
rather clock() which on windows returns the number of
clock ticks since the process started.
---
 ChangeLog   |    7 +++++++
 lib/times.c |    2 +-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fbb05bd..105befe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-10  Eli Zaretskii  <e...@gnu.org>
+
+	times: fix to return non constant value on MS-Windows
+	* lib/times.c (times): Don't use the process creation time,
+	rather clock() which on windows returns the number of
+	clock ticks since the process started.
+
 2014-06-09  Michael Goffioul  <michael.goffi...@gmail.com>
 
 	isatty: fix to work on windows 8
diff --git a/lib/times.c b/lib/times.c
index 87cbcd7..697f04a 100644
--- a/lib/times.c
+++ b/lib/times.c
@@ -62,5 +62,5 @@ times (struct tms * buffer)
   buffer->tms_cutime = 0;
   buffer->tms_cstime = 0;
 
-  return filetime2clock (creation_time);
+  return clock ();
 }
-- 
1.7.7.6

Reply via email to