Add <sys/auxv.h> and getauxval.
[glibc.git] / sysdeps / unix / sysv / linux / clock.c
blob9eddac849e41d72e516cfb91149a3f7e0ecc3a9e
1 /* Copyright (C) 1991, 1992, 1996, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <sys/times.h>
19 #include <time.h>
20 #include <unistd.h>
22 /* Return the time used by the program so far (user time + system time). */
23 clock_t
24 clock (void)
26 struct tms buf;
27 long clk_tck = __sysconf (_SC_CLK_TCK);
29 /* We don't check for errors here. The only error the kernel
30 returns is EFAULT if the value cannot be written to the struct we
31 pass a pointer to. Otherwise the kernel returns an `unsigned
32 long' value which is the number of jiffies since system start.
33 But this number can be negative (when read as `long') when the
34 system is up for some time. Ignoring errors should therefore
35 have no negative impacts but solve the problem. */
36 __times (&buf);
38 return
39 (clk_tck <= CLOCKS_PER_SEC)
40 ? ((unsigned long) buf.tms_utime + buf.tms_stime) * (CLOCKS_PER_SEC
41 / clk_tck)
42 : ((unsigned long) buf.tms_utime + buf.tms_stime) / (clk_tck
43 / CLOCKS_PER_SEC);