| 1 |
/* |
| 2 |
* Check: a unit test framework for C |
| 3 |
* Copyright (C) 2001, 2002 Arien Malec |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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, |
| 18 |
* MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "libcompat.h" |
| 22 |
|
| 23 |
int |
| 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) |
| 28 |
{ |
| 29 |
#ifdef HAVE_SETITIMER |
| 30 |
/* |
| 31 |
* If the system does not have timer_settime() but does have |
| 32 |
* setitimer() use that instead of alarm(). |
| 33 |
*/ |
| 34 |
struct itimerval interval; |
| 35 |
|
| 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; |
| 40 |
|
| 41 |
return setitimer (ITIMER_REAL, &interval, NULL); |
| 42 |
#else |
| 43 |
int seconds = new_value->it_value.tv_sec; |
| 44 |
|
| 45 |
/* |
| 46 |
* As the alarm() call has only second precision, if the caller |
| 47 |
* specifies partial seconds, we round up to the nearest second. |
| 48 |
*/ |
| 49 |
if (new_value->it_value.tv_nsec > 0) { |
| 50 |
seconds += 1; |
| 51 |
} |
| 52 |
|
| 53 |
alarm (seconds); |
| 54 |
|
| 55 |
return 0; |
| 56 |
#endif |
| 57 |
} |