]>
Commit | Line | Data |
---|---|---|
2f4f3bd4 | 1 | /* clock_gettime -- Get current time from a POSIX clockid_t. Linux version. |
d614a753 | 2 | Copyright (C) 2003-2020 Free Software Foundation, Inc. |
ad0e8eb0 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 | |
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. | |
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 | |
13 | Lesser General Public License for more details. | |
14 | ||
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/>. */ |
ad0e8eb0 UD |
18 | |
19 | #include <sysdep.h> | |
ec138c67 | 20 | #include <kernel-features.h> |
2f4f3bd4 | 21 | #include <errno.h> |
6ba85a6d | 22 | #include <time.h> |
2f4f3bd4 | 23 | #include "kernel-posix-cpu-timers.h" |
ad0e8eb0 | 24 | |
f534255e AZ |
25 | #ifdef HAVE_CLOCK_GETTIME_VSYSCALL |
26 | # define HAVE_VSYSCALL | |
a77d3c17 | 27 | #endif |
f534255e | 28 | #include <sysdep-vdso.h> |
2f4f3bd4 | 29 | |
7b5af2d8 ZW |
30 | #include <shlib-compat.h> |
31 | ||
b06f4c00 WD |
32 | /* Get current value of CLOCK and store it in TP. */ |
33 | int | |
ec138c67 AF |
34 | __clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp) |
35 | { | |
36 | #ifdef __ASSUME_TIME64_SYSCALLS | |
37 | # ifndef __NR_clock_gettime64 | |
38 | # define __NR_clock_gettime64 __NR_clock_gettime | |
39 | # define __vdso_clock_gettime64 __vdso_clock_gettime | |
40 | # endif | |
41 | return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); | |
42 | #else | |
43 | # if defined HAVE_CLOCK_GETTIME64_VSYSCALL | |
44 | int ret64 = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); | |
45 | if (ret64 == 0 || errno != ENOSYS) | |
46 | return ret64; | |
47 | # endif | |
48 | struct timespec tp32; | |
49 | int ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32); | |
50 | if (ret == 0) | |
51 | *tp = valid_timespec_to_timespec64 (tp32); | |
52 | return ret; | |
53 | #endif | |
54 | } | |
55 | ||
56 | #if __TIMESIZE != 64 | |
57 | int | |
b06f4c00 WD |
58 | __clock_gettime (clockid_t clock_id, struct timespec *tp) |
59 | { | |
ec138c67 AF |
60 | int ret; |
61 | struct __timespec64 tp64; | |
62 | ||
63 | ret = __clock_gettime64 (clock_id, &tp64); | |
64 | ||
65 | if (ret == 0) | |
66 | { | |
67 | if (! in_time_t_range (tp64.tv_sec)) | |
68 | { | |
69 | __set_errno (EOVERFLOW); | |
70 | return -1; | |
71 | } | |
72 | ||
73 | *tp = valid_timespec64_to_timespec (tp64); | |
74 | } | |
75 | ||
76 | return ret; | |
b06f4c00 | 77 | } |
ec138c67 | 78 | #endif |
b06f4c00 | 79 | libc_hidden_def (__clock_gettime) |
7b5af2d8 ZW |
80 | |
81 | versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17); | |
82 | /* clock_gettime moved to libc in version 2.17; | |
83 | old binaries may expect the symbol version it had in librt. */ | |
84 | #if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17) | |
85 | strong_alias (__clock_gettime, __clock_gettime_2); | |
86 | compat_symbol (libc, __clock_gettime_2, clock_gettime, GLIBC_2_2); | |
87 | #endif |