xref: /minix3/minix/lib/libc/sys/setitimer.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include <sys/cdefs.h>
2*433d6423SLionel Sambuc #include "namespace.h"
3*433d6423SLionel Sambuc #include <lib.h>
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include <string.h>
6*433d6423SLionel Sambuc #include <sys/time.h>
7*433d6423SLionel Sambuc 
8*433d6423SLionel Sambuc /*
9*433d6423SLionel Sambuc  * This is the implementation of the function to
10*433d6423SLionel Sambuc  * invoke the interval timer setting system call.
11*433d6423SLionel Sambuc  */
setitimer(int which,const struct itimerval * __restrict value,struct itimerval * __restrict ovalue)12*433d6423SLionel Sambuc int setitimer(int which, const struct itimerval *__restrict value,
13*433d6423SLionel Sambuc 		struct itimerval *__restrict ovalue)
14*433d6423SLionel Sambuc {
15*433d6423SLionel Sambuc   message m;
16*433d6423SLionel Sambuc 
17*433d6423SLionel Sambuc   /* A null pointer for 'value' would make setitimer behave like getitimer,
18*433d6423SLionel Sambuc    * which is not according to the specification, so disallow null pointers.
19*433d6423SLionel Sambuc    */
20*433d6423SLionel Sambuc   if (value == NULL) {
21*433d6423SLionel Sambuc 	errno = EINVAL;
22*433d6423SLionel Sambuc 	return -1;
23*433d6423SLionel Sambuc   }
24*433d6423SLionel Sambuc 
25*433d6423SLionel Sambuc   memset(&m, 0, sizeof(m));
26*433d6423SLionel Sambuc   m.m_lc_pm_itimer.which = which;
27*433d6423SLionel Sambuc   m.m_lc_pm_itimer.value = (vir_bytes)value;
28*433d6423SLionel Sambuc   m.m_lc_pm_itimer.ovalue = (vir_bytes)ovalue;
29*433d6423SLionel Sambuc 
30*433d6423SLionel Sambuc   return _syscall(PM_PROC_NR, PM_ITIMER, &m);
31*433d6423SLionel Sambuc }
32*433d6423SLionel Sambuc 
33*433d6423SLionel Sambuc #if defined(__minix) && defined(__weak_alias)
34*433d6423SLionel Sambuc __weak_alias(setitimer, __setitimer50)
35*433d6423SLionel Sambuc #endif
36