xref: /minix/minix/lib/libsys/sys_setalarm.c (revision 00e393ca)
1 #include "syslib.h"
2 
3 /*
4  * Ask the kernel to schedule a synchronous alarm for the caller, using either
5  * an absolute or a relative number of clock ticks.  The new alarm replaces any
6  * previously set alarm.  If a relative expiry time of zero is given, the
7  * current alarm is stopped.  Return OK or a negative error code.  On success,
8  * optionally return the time left on the previous timer (TMR_NEVER if none was
9  * set) and the current time.
10  */
11 int
12 sys_setalarm2(clock_t exp_time, int abs_time, clock_t * time_left,
13 	clock_t * uptime)
14 {
15 	message m;
16 	int r;
17 
18 	m.m_lsys_krn_sys_setalarm.exp_time = exp_time; /* expiration time */
19 	m.m_lsys_krn_sys_setalarm.abs_time = abs_time; /* time is absolute? */
20 
21 	if ((r = _kernel_call(SYS_SETALARM, &m)) != OK)
22 		return r;
23 
24 	if (time_left != NULL)
25 		*time_left = m.m_lsys_krn_sys_setalarm.time_left;
26 	if (uptime != NULL)
27 		*uptime = m.m_lsys_krn_sys_setalarm.uptime;
28 	return OK;
29 }
30