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