xref: /haiku/src/system/libroot/posix/unistd/ualarm.c (revision aff60bb217827097c13d643275fdf1f1c66e7f17)
1 /*
2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
5 
6 
7 #include <unistd.h>
8 #include <syscalls.h>
9 #include <errno.h>
10 
11 
12 uint
13 ualarm(uint usec, uint interval)
14 {
15 	struct itimerval value, oldValue;
16 
17 	value.it_value.tv_sec = 0;
18 	value.it_value.tv_usec = usec;
19 	value.it_interval.tv_sec = 0;
20 	value.it_interval.tv_usec = interval;
21 
22 	if (setitimer(ITIMER_REAL, &value, &oldValue) < 0)
23 		return -1;
24 
25 	return (oldValue.it_value.tv_sec * 1000000) + oldValue.it_value.tv_usec;
26 }
27