[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Return value of 'times' on MS-Windows is constant and overflows

From: Eli Zaretskii
Subject: Return value of 'times' on MS-Windows is constant and overflows
Date: Sun, 08 Jun 2014 18:23:54 +0300

The gnulib 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.

This has 2 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 by 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.

To fix both issues, I suggest the following simple change:

--- lib/times.c~0       2014-02-15 01:00:33 +0200
+++ lib/times.c 2014-06-08 18:12:53 +0300
@@ -62,5 +62,5 @@ times (struct tms * buffer)
   buffer->tms_cutime = 0;
   buffer->tms_cstime = 0;
-  return filetime2clock (creation_time);
+  return clock ();

The function 'clock' in its Windows implementation returns the number
of clock ticks since the time the calling process started.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]