Back to index

glibc  2.9
clock.c File Reference
#include <sys/times.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.


clock_t clock (void)

Function Documentation

clock_t clock ( void  )

Definition at line 25 of file clock.c.

  struct tms buf;
  long clk_tck = __sysconf (_SC_CLK_TCK);

  /* We don't check for errors here.  The only error the kernel
     returns is EFAULT if the value cannot be written to the struct we
     pass a pointer to.  Otherwise the kernel returns an `unsigned
     long' value which is the number of jiffies since system start.
     But this number can be negative (when read as `long') when the
     system is up for some time.  Ignoring errors should therefore
     have no negative impacts but solve the problem.  */
  __times (&buf);

    (clk_tck <= CLOCKS_PER_SEC)
    ? ((unsigned long) buf.tms_utime + buf.tms_stime) * (CLOCKS_PER_SEC
                                                  / clk_tck)
    : ((unsigned long) buf.tms_utime + buf.tms_stime) / (clk_tck
                                                  / CLOCKS_PER_SEC);

Here is the call graph for this function: