]>
sourceware.org Git - glibc.git/blob - sysdeps/unix/sysv/linux/clock_gettime.c
f10a289f791b00b9d333750f6b861b14d674800a
1 /* clock_gettime -- Get current time from a POSIX clockid_t. Linux version.
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include <kernel-features.h>
23 #include "kernel-posix-cpu-timers.h"
24 #include <sysdep-vdso.h>
25 #include <shlib-compat.h>
27 /* Get current value of CLOCK and store it in TP. */
29 __clock_gettime64 (clockid_t clock_id
, struct __timespec64
*tp
)
33 #ifndef __NR_clock_gettime64
34 # define __NR_clock_gettime64 __NR_clock_gettime
37 #ifdef HAVE_CLOCK_GETTIME64_VSYSCALL
38 int (*vdso_time64
) (clockid_t clock_id
, struct __timespec64
*tp
)
39 = GLRO(dl_vdso_clock_gettime64
);
40 if (vdso_time64
!= NULL
)
42 r
= INTERNAL_VSYSCALL_CALL (vdso_time64
, 2, clock_id
, tp
);
45 return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
);
49 #ifdef HAVE_CLOCK_GETTIME_VSYSCALL
50 int (*vdso_time
) (clockid_t clock_id
, struct timespec
*tp
)
51 = GLRO(dl_vdso_clock_gettime
);
52 if (vdso_time
!= NULL
)
55 r
= INTERNAL_VSYSCALL_CALL (vdso_time
, 2, clock_id
, &tp32
);
56 if (r
== 0 && tp32
.tv_sec
>= 0)
58 *tp
= valid_timespec_to_timespec64 (tp32
);
62 return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
);
64 /* Fallback to syscall if the 32-bit time_t vDSO returns overflows. */
68 r
= INTERNAL_SYSCALL_CALL (clock_gettime64
, clock_id
, tp
);
72 return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
);
74 #ifndef __ASSUME_TIME64_SYSCALLS
75 /* Fallback code that uses 32-bit support. */
77 r
= INTERNAL_SYSCALL_CALL (clock_gettime
, clock_id
, &tp32
);
80 *tp
= valid_timespec_to_timespec64 (tp32
);
85 return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r
);
89 libc_hidden_def (__clock_gettime64
)
92 __clock_gettime (clockid_t clock_id
, struct timespec
*tp
)
95 struct __timespec64 tp64
;
97 ret
= __clock_gettime64 (clock_id
, &tp64
);
101 if (! in_time_t_range (tp64
.tv_sec
))
103 __set_errno (EOVERFLOW
);
107 *tp
= valid_timespec64_to_timespec (tp64
);
113 libc_hidden_def (__clock_gettime
)
115 versioned_symbol (libc
, __clock_gettime
, clock_gettime
, GLIBC_2_17
);
116 /* clock_gettime moved to libc in version 2.17;
117 old binaries may expect the symbol version it had in librt. */
118 #if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17)
119 strong_alias (__clock_gettime
, __clock_gettime_2
);
120 compat_symbol (libc
, __clock_gettime_2
, clock_gettime
, GLIBC_2_2
);
This page took 0.049403 seconds and 6 git commands to generate.