xref: /csrg-svn/usr.bin/f77/libU77/alarm_.c (revision 5353)
1*5353Sdlw /*
2*5353Sdlw char id_alarm[] = "@(#)alarm_.c	1.1";
3*5353Sdlw  *
4*5353Sdlw  * set an alarm time, arrange for user specified action, and return.
5*5353Sdlw  *
6*5353Sdlw  * calling sequence:
7*5353Sdlw  *	integer	flag
8*5353Sdlw  *	external alfunc
9*5353Sdlw  *	lastiv = alarm (intval, alfunc)
10*5353Sdlw  * where:
11*5353Sdlw  *	intval	= the alarm interval in seconds; 0 turns off the alarm.
12*5353Sdlw  *	alfunc	= the function to be called after the alarm interval,
13*5353Sdlw  *
14*5353Sdlw  *	The returned value will be the time remaining on the last alarm.
15*5353Sdlw  */
16*5353Sdlw 
17*5353Sdlw #include <signal.h>
18*5353Sdlw 
19*5353Sdlw long alarm_(sec, proc)
20*5353Sdlw long	*sec;
21*5353Sdlw int	(* proc)();
22*5353Sdlw {
23*5353Sdlw 	register long	lt;
24*5353Sdlw 
25*5353Sdlw 	lt = alarm(1000);	/* time to maneuver */
26*5353Sdlw 
27*5353Sdlw 	if (*sec)
28*5353Sdlw 		signal(SIGALRM, proc);
29*5353Sdlw 
30*5353Sdlw 	alarm(*sec);
31*5353Sdlw 	return(lt);
32*5353Sdlw }
33