xref: /csrg-svn/lib/libc/gen/alarm.c (revision 26541)
122079Smckusick /*
222079Smckusick  * Copyright (c) 1983 Regents of the University of California.
322079Smckusick  * All rights reserved.  The Berkeley software License Agreement
422079Smckusick  * specifies the terms and conditions for redistribution.
522079Smckusick  */
612973Ssam 
7*26541Sdonn #if defined(LIBC_SCCS) && !defined(lint)
8*26541Sdonn static char sccsid[] = "@(#)alarm.c	5.2 (Berkeley) 03/09/86";
9*26541Sdonn #endif LIBC_SCCS and not lint
1022079Smckusick 
1112973Ssam /*
1212973Ssam  * Backwards compatible alarm.
1312973Ssam  */
1412973Ssam #include <sys/time.h>
1512973Ssam 
1612973Ssam alarm(secs)
1712973Ssam 	int secs;
1812973Ssam {
1912973Ssam 	struct itimerval it, oitv;
2012973Ssam 	register struct itimerval *itp = &it;
2112973Ssam 
2212973Ssam 	timerclear(&itp->it_interval);
2312973Ssam 	itp->it_value.tv_sec = secs;
2412973Ssam 	itp->it_value.tv_usec = 0;
2512973Ssam 	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
2612973Ssam 		return (-1);
2716215Sralph 	if (oitv.it_value.tv_usec)
2816215Sralph 		oitv.it_value.tv_sec++;
2912973Ssam 	return (oitv.it_value.tv_sec);
3012973Ssam }
31