]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/alarm.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / alarm.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * alarm() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11 #include <unistd.h>
12
13 #ifdef __NR_alarm
14 _syscall1(unsigned int, alarm, unsigned int, seconds)
15 #else
16 # include <sys/time.h>
17
18 unsigned int alarm(unsigned int seconds)
19 {
20         struct itimerval old, new;
21         unsigned int retval;
22
23         new.it_value.tv_usec = 0;
24         new.it_interval.tv_sec = 0;
25         new.it_interval.tv_usec = 0;
26         new.it_value.tv_sec = (long int) seconds;
27         if (setitimer(ITIMER_REAL, &new, &old) < 0) {
28                 return 0;
29         }
30         retval = old.it_value.tv_sec;
31         if (old.it_value.tv_usec) {
32                 ++retval;
33         }
34         return retval;
35 }
36 #endif
37 libc_hidden_def(alarm)