]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libc_backends/lib/l4re/lib/clock_settime.c
44894d5682f3c0b4d952f457b5aa180dc266a694
[l4.git] / l4 / pkg / libc_backends / lib / l4re / lib / clock_settime.c
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU Lesser General Public License 2.1.
7  * Please see the COPYING-LGPL-2.1 file for details.
8  */
9
10 #include <errno.h>
11 #include <inttypes.h>
12 #include <time.h>
13 #include <l4/re/env.h>
14 #include <l4/sys/kip.h>
15
16 #include "clocks.h"
17
18 typedef int Get_clock(const struct timespec *);
19 extern uint64_t __libc_l4_rt_clock_offset;
20
21 static int rt_clock_settime(const struct timespec *tp)
22 {
23   uint64_t clock;
24
25   clock = tp->tv_sec * 1000000 + tp->tv_nsec / 1000;
26   __libc_l4_rt_clock_offset = clock - l4re_kip()->clock;
27   return 0;
28 }
29
30 Get_clock *__libc_l4_settime[4] =
31 {
32   [CLOCK_REALTIME]  = rt_clock_settime,
33 };
34
35 int clock_settime(clockid_t clk_id, const struct timespec *tp)
36 {
37   if (clk_id >= NCLOCKS || !__libc_l4_settime[clk_id])
38     {
39       errno = ENODEV;
40       return -1;
41     }
42
43   return __libc_l4_settime[clk_id](tp);
44 }
45