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