xref: /csrg-svn/usr.bin/f77/libU77/alarm_.c (revision 23004)
15353Sdlw /*
2*23004Skre  * Copyright (c) 1980 Regents of the University of California.
3*23004Skre  * All rights reserved.  The Berkeley software License Agreement
4*23004Skre  * specifies the terms and conditions for redistribution.
55353Sdlw  *
6*23004Skre  *	@(#)alarm_.c	5.1	06/07/85
7*23004Skre  */
8*23004Skre 
9*23004Skre /*
105353Sdlw  * set an alarm time, arrange for user specified action, and return.
115353Sdlw  *
125353Sdlw  * calling sequence:
135353Sdlw  *	integer	flag
145353Sdlw  *	external alfunc
155353Sdlw  *	lastiv = alarm (intval, alfunc)
165353Sdlw  * where:
175353Sdlw  *	intval	= the alarm interval in seconds; 0 turns off the alarm.
185353Sdlw  *	alfunc	= the function to be called after the alarm interval,
195353Sdlw  *
205353Sdlw  *	The returned value will be the time remaining on the last alarm.
215353Sdlw  */
225353Sdlw 
235353Sdlw #include <signal.h>
245353Sdlw 
255353Sdlw long alarm_(sec, proc)
265353Sdlw long	*sec;
275353Sdlw int	(* proc)();
285353Sdlw {
295353Sdlw 	register long	lt;
305353Sdlw 
315353Sdlw 	lt = alarm(1000);	/* time to maneuver */
325353Sdlw 
335353Sdlw 	if (*sec)
345353Sdlw 		signal(SIGALRM, proc);
355353Sdlw 
365353Sdlw 	alarm(*sec);
375353Sdlw 	return(lt);
385353Sdlw }
39