1 | /* clock_adjtime -- tune kernel clock. |
2 | Copyright (C) 2020 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 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 <sys/timex.h> |
24 | #include <kernel-features.h> |
25 | |
26 | int |
27 | __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64) |
28 | { |
29 | #ifdef __ASSUME_TIME64_SYSCALLS |
30 | # ifndef __NR_clock_adjtime64 |
31 | # define __NR_clock_adjtime64 __NR_clock_adjtime |
32 | # endif |
33 | return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64); |
34 | #else |
35 | int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64); |
36 | if (errno != ENOSYS) |
37 | return ret; |
38 | |
39 | if (tx64->modes & ADJ_SETOFFSET |
40 | && ! in_time_t_range (tx64->time.tv_sec)) |
41 | { |
42 | __set_errno (EOVERFLOW); |
43 | return -1; |
44 | } |
45 | |
46 | struct timex tx32 = valid_timex64_to_timex (*tx64); |
47 | int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32); |
48 | if (retval >= 0) |
49 | *tx64 = valid_timex_to_timex64 (tx32); |
50 | |
51 | return retval; |
52 | #endif |
53 | } |
54 | |
55 | #if __TIMESIZE != 64 |
56 | libc_hidden_def (__clock_adjtime64) |
57 | |
58 | int |
59 | __clock_adjtime (const clockid_t clock_id, struct timex *tx) |
60 | { |
61 | struct __timex64 tx64; |
62 | int retval; |
63 | |
64 | tx64 = valid_timex_to_timex64 (*tx); |
65 | retval = __clock_adjtime64 (clock_id, &tx64); |
66 | if (retval >= 0) |
67 | *tx = valid_timex64_to_timex (tx64); |
68 | |
69 | return retval; |
70 | } |
71 | #endif |
72 | libc_hidden_def (__clock_adjtime); |
73 | strong_alias (__clock_adjtime, clock_adjtime) |
74 | |