manual page first distributed with 4.2BSD
[unix-history] / usr / src / lib / libc / gen / ualarm.c
CommitLineData
63dcf418
S
1/* @(#)ualarm.c 1.1 (Berkeley) %G% */
2
3#include <sys/time.h>
4
5#define USPS 1000000 /* # of microseconds in a second */
6
7/*
8 * Generate a SIGALRM signal in ``usecs'' microseconds.
9 * If ``reload'' is non-zero, keep generating SIGALRM
10 * every ``reload'' microseconds after the first signal.
11 */
12unsigned
13ualarm(usecs, reload)
14 register unsigned usecs;
15 register unsigned reload;
16{
17 struct itimerval new, old;
18
19 new.it_interval.tv_usec = reload % USPS;
20 new.it_interval.tv_sec = reload / USPS;
21
22 new.it_value.tv_usec = usecs % USPS;
23 new.it_value.tv_sec = usecs / USPS;
24
25 if (setitimer(ITIMER_REAL, &new, &old) == 0)
26 return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
27 /* else */
28 return (-1);
29}