diff options
Diffstat (limited to '')
-rw-r--r-- | usr/klibc/alarm.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/usr/klibc/alarm.c b/usr/klibc/alarm.c new file mode 100644 index 0000000..8bd74c5 --- /dev/null +++ b/usr/klibc/alarm.c @@ -0,0 +1,25 @@ +/* + * alarm.c + */ + +#include <sys/time.h> +#include <sys/syscall.h> + +#ifndef __NR_alarm + +/* Emulate alarm() via setitimer() */ + +unsigned int alarm(unsigned int seconds) +{ + struct itimerval iv; + + iv.it_interval.tv_sec = iv.it_interval.tv_usec = 0; + iv.it_value.tv_sec = seconds; + iv.it_value.tv_usec = 0; + + setitimer(ITIMER_REAL, &iv, &iv); + + return iv.it_value.tv_sec + (iv.it_value.tv_usec ? 1 : 0); +} + +#endif |