etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / adjtime.c
blob37db1aa0b0d3be6ebbf2c36a78c1d9038c26b7d3
1 #include <sys/cdefs.h>
2 #include <lib.h>
3 #include "namespace.h"
5 #include <string.h>
6 #include <sys/time.h>
7 #include <time.h>
9 #ifdef __weak_alias
10 __weak_alias(adjtime, __adjtime50);
11 #endif
13 int adjtime(const struct timeval *delta, struct timeval *olddelta)
15 message m;
17 memset(&m, 0, sizeof(m));
18 m.m_lc_pm_time.clk_id = CLOCK_REALTIME;
19 m.m_lc_pm_time.now = 0; /* use adjtime() method to slowly adjust the clock. */
20 m.m_lc_pm_time.sec = delta->tv_sec;
21 m.m_lc_pm_time.nsec = delta->tv_usec * 1000; /* convert usec to nsec */
23 if (_syscall(PM_PROC_NR, PM_CLOCK_SETTIME, &m) < 0)
24 return -1;
26 if (olddelta != NULL) {
27 /* the kernel returns immediately and the adjustment happens in the
28 * background. Also, any currently running adjustment is stopped by
29 * another call to adjtime(2), so the only values possible on Minix
30 * for olddelta are those of delta.
32 olddelta->tv_sec = delta->tv_sec;
33 olddelta->tv_usec = delta->tv_usec;
36 return 0;