xref: /titanic_50/usr/src/lib/libc/port/gen/ualarm.c (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
9 /*	  All Rights Reserved  	*/
10 
11 
12 /*
13  * Copyright (c) 1985 Regents of the University of California.
14  * All rights reserved.  The Berkeley software License Agreement
15  * specifies the terms and conditions for redistribution.
16  */
17 
18 #include "synonyms.h"
19 #include <sys/types.h>
20 #include <sys/time.h>
21 #include <unistd.h>
22 
23 #define	USPS	1000000		/* # of microseconds in a second */
24 
25 /*
26  * Generate a SIGALRM signal in ``usecs'' microseconds.
27  * If ``reload'' is non-zero, keep generating SIGALRM
28  * every ``reload'' microseconds after the first signal.
29  */
30 useconds_t
31 ualarm(useconds_t usecs, useconds_t reload)
32 {
33 	struct itimerval new, old;
34 
35 	new.it_interval.tv_usec = reload % USPS;
36 	new.it_interval.tv_sec = reload / USPS;
37 
38 	new.it_value.tv_usec = usecs % USPS;
39 	new.it_value.tv_sec = usecs / USPS;
40 
41 	if (setitimer(ITIMER_REAL, &new, &old) != 0)
42 		return (0);	/* no errors are defined */
43 	return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
44 }
45