xref: /haiku/src/system/libroot/posix/unistd/alarm.c (revision 25a7b01d15612846f332751841da3579db313082)
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 <errno.h>
8 #include <unistd.h>
9 #include <sys/time.h>
10 
11 #include <errno_private.h>
12 #include <syscalls.h>
13 
14 
15 uint
16 alarm(unsigned int sec)
17 {
18 	struct itimerval value, oldValue;
19 
20 	value.it_interval.tv_sec = value.it_interval.tv_usec = 0;
21 	value.it_value.tv_sec = sec;
22 	value.it_value.tv_usec = 0;
23 	if (setitimer(ITIMER_REAL, &value, &oldValue) < 0)
24 		return -1;
25 
26 	if (oldValue.it_value.tv_usec)
27 		oldValue.it_value.tv_sec++;
28 
29 	return oldValue.it_value.tv_sec;
30 }
31 
32