2 * Check: a unit test framework for C
3 * Copyright (C) 2001, 2002 Arien Malec
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21 #include "libcompat.h"
24 timer_settime (timer_t timerid CK_ATTRIBUTE_UNUSED,
25 int flags CK_ATTRIBUTE_UNUSED,
26 const struct itimerspec *new_value,
27 struct itimerspec *old_value CK_ATTRIBUTE_UNUSED)
31 * If the system does not have timer_settime() but does have
32 * setitimer() use that instead of alarm().
34 struct itimerval interval;
36 interval.it_value.tv_sec = new_value->it_value.tv_sec;
37 interval.it_value.tv_usec = new_value->it_value.tv_nsec / 1000;
38 interval.it_interval.tv_sec = new_value->it_interval.tv_sec;
39 interval.it_interval.tv_usec = new_value->it_interval.tv_nsec / 1000;
41 return setitimer (ITIMER_REAL, &interval, NULL);
43 int seconds = new_value->it_value.tv_sec;
46 * As the alarm() call has only second precision, if the caller
47 * specifies partial seconds, we round up to the nearest second.
49 if (new_value->it_value.tv_nsec > 0) {