]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/ia64/has_cpuclock.c
nptl: Remove pthread_clock_gettime pthread_clock_settime
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / ia64 / has_cpuclock.c
1 /* Copyright (C) 2000-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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/>. */
17
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <not-cancel.h>
24
25 static int itc_usable;
26
27 static int
28 has_cpuclock (void)
29 {
30 if (__builtin_expect (itc_usable == 0, 0))
31 {
32 int newval = 1;
33 int fd = __open_nocancel ("/proc/sal/itc_drift", O_RDONLY);
34 if (__builtin_expect (fd != -1, 1))
35 {
36 char buf[16];
37 /* We expect the file to contain a single digit followed by
38 a newline. If the format changes we better not rely on
39 the file content. */
40 if (__read_nocancel (fd, buf, sizeof buf) != 2
41 || buf[0] != '0' || buf[1] != '\n')
42 newval = -1;
43
44 __close_nocancel_nostatus (fd);
45 }
46
47 itc_usable = newval;
48 }
49
50 return itc_usable;
51 }