1/* settimeofday -- set system time - Linux version supporting 64 bit time.
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 <https://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <time.h>
21#include <sys/time.h>
22
23/* Set the current time of day and timezone information.
24 This call is restricted to the super-user. */
25int
26__settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
27{
28 /* Backwards compatibility for setting the UTC offset. */
29 if (__glibc_unlikely (tz != 0))
30 {
31 if (tv != 0)
32 {
33 __set_errno (EINVAL);
34 return -1;
35 }
36 return __settimezone (tz: tz);
37 }
38
39 struct __timespec64 ts = timeval64_to_timespec64 (tv64: *tv);
40 return __clock_settime64 (CLOCK_REALTIME, &ts);
41}
42
43#if __TIMESIZE != 64
44libc_hidden_def (__settimeofday64)
45
46int
47__settimeofday (const struct timeval *tv, const struct timezone *tz)
48{
49 if (__glibc_unlikely (tv == NULL))
50 return __settimeofday64 (NULL, tz);
51 else
52 {
53 struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
54 return __settimeofday64 (&tv64, tz);
55 }
56}
57#endif
58weak_alias (__settimeofday, settimeofday);
59

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