xref: /titanic_50/usr/src/lib/libbc/libc/gen/common/ualarm.c (revision ba7866cd2cbdf574f47d4e38a1301b90744dd677)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 	  /* from UCB 5.1 85/06/05 */
3 
4 /*
5  * Copyright (c) 1985 Regents of the University of California.
6  * All rights reserved.  The Berkeley software License Agreement
7  * specifies the terms and conditions for redistribution.
8  */
9 
10 #include <sys/time.h>
11 
12 #define	USPS	1000000		/* # of microseconds in a second */
13 
14 /*
15  * Generate a SIGALRM signal in ``usecs'' microseconds.
16  * If ``reload'' is non-zero, keep generating SIGALRM
17  * every ``reload'' microseconds after the first signal.
18  */
19 unsigned
20 ualarm(usecs, reload)
21 	register unsigned usecs;
22 	register unsigned reload;
23 {
24 	struct itimerval new, old;
25 
26 	new.it_interval.tv_usec = reload % USPS;
27 	new.it_interval.tv_sec = reload / USPS;
28 
29 	new.it_value.tv_usec = usecs % USPS;
30 	new.it_value.tv_sec = usecs / USPS;
31 
32 	if (setitimer(ITIMER_REAL, &new, &old) == 0)
33 		return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
34 	/* else */
35 		return (-1);
36 }
37