]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/clock.c
y2038: Replace __clock_gettime with __clock_gettime64
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / clock.c
CommitLineData
58206c68 1/* Return the time used by the program so far (user time + system time).
d614a753 2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
6d52618b
UD
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
6d52618b
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
6d52618b 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
6d52618b
UD
18
19#include <sys/times.h>
20#include <time.h>
21#include <unistd.h>
22
6d52618b
UD
23clock_t
24clock (void)
25{
e9698175 26 struct __timespec64 ts;
58206c68 27
57ada0e7
L
28 _Static_assert (CLOCKS_PER_SEC == 1000000,
29 "CLOCKS_PER_SEC should be 1000000");
30
e9698175 31 if (__glibc_unlikely (__clock_gettime64 (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0))
58206c68
SP
32 return (clock_t) -1;
33
34 return (ts.tv_sec * CLOCKS_PER_SEC
35 + ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC));
6d52618b 36}