1/* Copyright (C) 2003-2022 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 License as
6 published by the Free Software Foundation; either version 2.1 of the
7 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; see the file COPYING.LIB. If
16 not, see <https://www.gnu.org/licenses/>. */
17
18#include <errno.h>
19#include <stdlib.h>
20#include <time.h>
21#include <sysdep.h>
22#include <kernel-features.h>
23#include "kernel-posix-timers.h"
24#include <shlib-compat.h>
25
26#if !TIMER_T_WAS_INT_COMPAT
27int
28___timer_gettime64 (timer_t timerid, struct __itimerspec64 *value)
29{
30 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
31
32# ifndef __NR_timer_gettime64
33# define __NR_timer_gettime64 __NR_timer_gettime
34# endif
35 int ret = INLINE_SYSCALL_CALL (timer_gettime64, ktimerid, value);
36# ifndef __ASSUME_TIME64_SYSCALLS
37 if (ret == 0 || errno != ENOSYS)
38 return ret;
39
40 struct itimerspec its32;
41 ret = INLINE_SYSCALL_CALL (timer_gettime, ktimerid, &its32);
42 if (ret == 0)
43 {
44 value->it_interval = valid_timespec_to_timespec64 (its32.it_interval);
45 value->it_value = valid_timespec_to_timespec64 (its32.it_value);
46 }
47# endif
48 return ret;
49}
50
51# if __TIMESIZE == 64
52versioned_symbol (libc, ___timer_gettime64, timer_gettime, GLIBC_2_34);
53# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
54compat_symbol (librt, ___timer_gettime64, timer_gettime, GLIBC_2_2);
55# endif
56
57# else /* __TIMESIZE != 64 */
58libc_hidden_ver (___timer_gettime64, __timer_gettime64)
59versioned_symbol (libc, ___timer_gettime64, __timer_gettime64, GLIBC_2_34);
60
61int
62__timer_gettime (timer_t timerid, struct itimerspec *value)
63{
64 struct __itimerspec64 its64;
65 int retval = __timer_gettime64 (timerid, &its64);
66 if (retval == 0)
67 {
68 value->it_interval = valid_timespec64_to_timespec (its64.it_interval);
69 value->it_value = valid_timespec64_to_timespec (its64.it_value);
70 }
71
72 return retval;
73}
74versioned_symbol (libc, __timer_gettime, timer_gettime, GLIBC_2_34);
75
76# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
77compat_symbol (librt, __timer_gettime, timer_gettime, GLIBC_2_2);
78# endif
79# endif /* __TIMESIZE != 64 */
80
81#else /* TIMER_T_WAS_INT_COMPAT */
82
83extern __typeof (timer_gettime) __timer_gettime_new;
84libc_hidden_proto (__timer_gettime_new)
85
86int
87___timer_gettime_new (timer_t timerid, struct itimerspec *value)
88{
89 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
90
91 return INLINE_SYSCALL_CALL (timer_gettime, ktimerid, value);
92}
93versioned_symbol (libc, ___timer_gettime_new, timer_gettime, GLIBC_2_34);
94libc_hidden_ver (___timer_gettime_new, __timer_gettime_new)
95
96# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_3, GLIBC_2_34)
97compat_symbol (librt, ___timer_gettime_new, timer_gettime, GLIBC_2_3_3);
98# endif
99
100# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
101int
102__timer_gettime_old (int timerid, struct itimerspec *value)
103{
104 return __timer_gettime_new (__timer_compat_list[timerid], value);
105}
106compat_symbol (librt, __timer_gettime_old, timer_gettime, GLIBC_2_2);
107# endif
108
109#endif /* TIMER_T_WAS_INT_COMPAT */
110

source code of glibc/sysdeps/unix/sysv/linux/timer_gettime.c