xref: /original-bsd/lib/libc/gen/alarm.c (revision bac379f5)
1824ff4dfSmckusick /*
2*bac379f5Sbostic  * Copyright (c) 1983, 1993
3*bac379f5Sbostic  *	The Regents of the University of California.  All rights reserved.
49785d310Sbostic  *
5be25273bSbostic  * %sccs.include.redist.c%
6824ff4dfSmckusick  */
7824ff4dfSmckusick 
88ad967f1Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*bac379f5Sbostic static char sccsid[] = "@(#)alarm.c	8.1 (Berkeley) 06/04/93";
109785d310Sbostic #endif /* LIBC_SCCS and not lint */
11f3a9f492Ssam 
12f3a9f492Ssam /*
13f3a9f492Ssam  * Backwards compatible alarm.
14f3a9f492Ssam  */
15f3a9f492Ssam #include <sys/time.h>
16ae227ee3Sdonn #include <unistd.h>
17f3a9f492Ssam 
18ae227ee3Sdonn unsigned int
alarm(secs)19f3a9f492Ssam alarm(secs)
20ae227ee3Sdonn 	unsigned int secs;
21f3a9f492Ssam {
22f3a9f492Ssam 	struct itimerval it, oitv;
23f3a9f492Ssam 	register struct itimerval *itp = &it;
24f3a9f492Ssam 
25f3a9f492Ssam 	timerclear(&itp->it_interval);
26f3a9f492Ssam 	itp->it_value.tv_sec = secs;
27f3a9f492Ssam 	itp->it_value.tv_usec = 0;
28f3a9f492Ssam 	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
29f3a9f492Ssam 		return (-1);
30e486079fSralph 	if (oitv.it_value.tv_usec)
31e486079fSralph 		oitv.it_value.tv_sec++;
32f3a9f492Ssam 	return (oitv.it_value.tv_sec);
33f3a9f492Ssam }
34