xref: /original-bsd/lib/libc/gen/alarm.c (revision c8089215)
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.5 (Berkeley) 02/23/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 /*
13  * Backwards compatible alarm.
14  */
15 #include <sys/time.h>
16 #include <unistd.h>
17 
18 unsigned int
19 alarm(secs)
20 	unsigned int secs;
21 {
22 	struct itimerval it, oitv;
23 	register struct itimerval *itp = &it;
24 
25 	timerclear(&itp->it_interval);
26 	itp->it_value.tv_sec = secs;
27 	itp->it_value.tv_usec = 0;
28 	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
29 		return (-1);
30 	if (oitv.it_value.tv_usec)
31 		oitv.it_value.tv_sec++;
32 	return (oitv.it_value.tv_sec);
33 }
34