d09ba270c1bd4c2317e3f04a06c433478915bb6e
[platform/upstream/gstreamer.git] / libs / gst / check / libcheck / libcompat / timer_settime.c
1 #include "libcompat.h"
2
3 int
4 timer_settime (timer_t timerid CK_ATTRIBUTE_UNUSED,
5     int flags CK_ATTRIBUTE_UNUSED,
6     const struct itimerspec *new_value,
7     struct itimerspec *old_value CK_ATTRIBUTE_UNUSED)
8 {
9 #ifdef HAVE_SETITIMER
10   /*
11    * If the system does not have timer_settime() but does have
12    * setitimer() use that instead of alarm().
13    */
14   struct itimerval interval;
15
16   interval.it_value.tv_sec = new_value->it_value.tv_sec;
17   interval.it_value.tv_usec = new_value->it_value.tv_nsec / 1000;
18   interval.it_interval.tv_sec = new_value->it_interval.tv_sec;
19   interval.it_interval.tv_usec = new_value->it_interval.tv_nsec / 1000;
20
21   return setitimer (ITIMER_REAL, &interval, NULL);
22 #else
23   int seconds = new_value->it_value.tv_sec;
24
25   /* 
26    * As the alarm() call has only second precision, if the caller
27    * specifies partial seconds, we round up to the nearest second.
28    */
29   if (new_value->it_value.tv_nsec > 0) {
30     seconds += 1;
31   }
32
33   alarm (seconds);
34
35   return 0;
36 #endif
37 }