1/* setitimer -- Set the state of an interval timer. Linux/32 version.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
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
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <time.h>
20#include <sys/time.h>
21#include <sys/types.h>
22#include <sysdep.h>
23#include <tv32-compat.h>
24
25int
26__setitimer64 (__itimer_which_t which,
27 const struct __itimerval64 *restrict new_value,
28 struct __itimerval64 *restrict old_value)
29{
30#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
31 return INLINE_SYSCALL_CALL (setitimer, which, new_value, old_value);
32#else
33 struct __itimerval32 new_value_32;
34
35 if (! in_int32_t_range (new_value->it_interval.tv_sec)
36 || ! in_int32_t_range (new_value->it_value.tv_sec))
37 {
38 __set_errno (EOVERFLOW);
39 return -1;
40 }
41 new_value_32.it_interval
42 = valid_timeval64_to_timeval32 (new_value->it_interval);
43 new_value_32.it_value
44 = valid_timeval64_to_timeval32 (new_value->it_value);
45
46 if (old_value == NULL)
47 return INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, NULL);
48
49 struct __itimerval32 old_value_32;
50 if (INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, &old_value_32)
51 == -1)
52 return -1;
53
54 old_value->it_interval
55 = valid_timeval32_to_timeval64 (old_value_32.it_interval);
56 old_value->it_value
57 = valid_timeval32_to_timeval64 (old_value_32.it_value);
58 return 0;
59#endif
60}
61
62#if __TIMESIZE != 64
63libc_hidden_def (__setitimer64)
64int
65__setitimer (__itimer_which_t which,
66 const struct itimerval *restrict new_value,
67 struct itimerval *restrict old_value)
68{
69 int ret;
70 struct __itimerval64 new64, old64;
71
72 new64.it_interval
73 = valid_timeval_to_timeval64 (new_value->it_interval);
74 new64.it_value
75 = valid_timeval_to_timeval64 (new_value->it_value);
76
77 ret = __setitimer64 (which, &new64, old_value ? &old64 : NULL);
78
79 if (ret == 0 && old_value != NULL)
80 {
81 old_value->it_interval
82 = valid_timeval64_to_timeval (old64.it_interval);
83 old_value->it_value
84 = valid_timeval64_to_timeval (old64.it_value);
85 }
86
87 return ret;
88}
89#endif
90weak_alias (__setitimer, setitimer)
91

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