]> Savannah Git Hosting - gnulib.git/commitdiff
times: fix to return non constant value on MS-Windows
authorEli Zaretskii <eliz@gnu.org>
Tue, 10 Jun 2014 20:22:16 +0000 (21:22 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 10 Jun 2014 22:44:45 +0000 (23:44 +0100)
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
lib/times.c

index fbb05bd40d95474b1b5f64162b18f67e8b9aa0ed..105befe73471ea0b9fe594825ed14a91347852d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-10  Eli Zaretskii  <eliz@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.goffioul@gmail.com>
 
        isatty: fix to work on windows 8
index 87cbcd7f612f984335eb52f1f446480909361d70..697f04ab85eb5a7ce249e330b02f450d613ee052 100644 (file)
@@ -62,5 +62,5 @@ times (struct tms * buffer)
   buffer->tms_cutime = 0;
   buffer->tms_cstime = 0;
 
-  return filetime2clock (creation_time);
+  return clock ();
 }