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 <syscalls.h> 12 13 14 uint 15 alarm(unsigned int sec) 16 { 17 struct itimerval value, oldValue; 18 19 value.it_interval.tv_sec = value.it_interval.tv_usec = 0; 20 value.it_value.tv_sec = sec; 21 value.it_value.tv_usec = 0; 22 if (setitimer(ITIMER_REAL, &value, &oldValue) < 0) 23 return -1; 24 25 if (oldValue.it_value.tv_usec) 26 oldValue.it_value.tv_sec++; 27 28 return oldValue.it_value.tv_sec; 29 } 30 31