Files
haiku-beta6/src/system/libroot/posix/unistd/alarm.c
T

36 lines
632 B
C
Raw Normal View History

/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <syscalls.h>
uint
alarm(unsigned int sec)
{
struct itimerval value, oldValue;
int result;
value.it_interval.tv_sec = value.it_interval.tv_usec = 0;
value.it_value.tv_sec = sec;
value.it_value.tv_usec = 0;
result = setitimer(ITIMER_REAL, &value, &oldValue);
if (result < 0) {
errno = result;
return -1;
}
if (oldValue.it_value.tv_usec)
oldValue.it_value.tv_sec++;
return oldValue.it_value.tv_sec;
}