blob: cfd68fe1b13c1a4b90ef37134c462c67b39101c4 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* 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
14#ifdef __NR_alarm
15_syscall1(unsigned int, alarm, unsigned int, seconds)
16#else
17#include <sys/time.h>
18
19
20unsigned int alarm(unsigned int seconds)
21{
22 struct itimerval old, new;
23 unsigned int retval;
24
25 new.it_value.tv_usec = 0;
26 new.it_interval.tv_sec = 0;
27 new.it_interval.tv_usec = 0;
28 new.it_value.tv_sec = (long int) seconds;
29 if (setitimer(ITIMER_REAL, &new, &old) < 0) {
30 return 0;
31 }
32 retval = old.it_value.tv_sec;
33 if (old.it_value.tv_usec) {
34 ++retval;
35 }
36 return retval;
37}
38#endif
39libc_hidden_def(alarm)