1 /* Copyright (C) 1991-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
6    License as published by the Free Software Foundation; either
7    version 2.1 of the 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; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #include <errno.h>
19 #include <time.h>
20 #include <hurd.h>
21 #include <hurd/port.h>
22 #include <shlib-compat.h>
23 
24 /* Set the current time of day.
25    This call is restricted to the super-user.  */
26 int
__clock_settime(clockid_t clock_id,const struct timespec * ts)27 __clock_settime (clockid_t clock_id, const struct timespec *ts)
28 {
29   error_t err;
30   mach_port_t hostpriv;
31   time_value_t tv;
32 
33   if (clock_id != CLOCK_REALTIME
34       || ! valid_nanoseconds (ts->tv_nsec))
35     return __hurd_fail (EINVAL);
36 
37   err = __get_privileged_ports (&hostpriv, NULL);
38   if (err)
39     return __hurd_fail (EPERM);
40 
41   TIMESPEC_TO_TIME_VALUE (&tv, ts);
42   err = __host_set_time (hostpriv, tv);
43   __mach_port_deallocate (__mach_task_self (), hostpriv);
44 
45   return __hurd_fail (err);
46 }
47 libc_hidden_def (__clock_settime)
48 
49 versioned_symbol (libc, __clock_settime, clock_settime, GLIBC_2_17);
50 /* clock_settime moved to libc in version 2.17;
51    old binaries may expect the symbol version it had in librt.  */
52 #if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17)
53 strong_alias (__clock_settime, __clock_settime_2);
54 compat_symbol (libc, __clock_settime_2, clock_settime, GLIBC_2_2);
55 #endif
56