xref: /csrg-svn/lib/libc/gen/alarm.c (revision 42620)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)alarm.c	5.4 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 /*
13  * Backwards compatible alarm.
14  */
15 #include <sys/time.h>
16 
17 alarm(secs)
18 	int secs;
19 {
20 	struct itimerval it, oitv;
21 	register struct itimerval *itp = &it;
22 
23 	timerclear(&itp->it_interval);
24 	itp->it_value.tv_sec = secs;
25 	itp->it_value.tv_usec = 0;
26 	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
27 		return (-1);
28 	if (oitv.it_value.tv_usec)
29 		oitv.it_value.tv_sec++;
30 	return (oitv.it_value.tv_sec);
31 }
32