last-minute corrections
[unix-history] / usr / src / lib / libc / gen / ualarm.c
CommitLineData
b8f253e8
KM
1/*
2 * Copyright (c) 1985 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)ualarm.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
63dcf418
S
10
11#include <sys/time.h>
12
13#define USPS 1000000 /* # of microseconds in a second */
14
15/*
16 * Generate a SIGALRM signal in ``usecs'' microseconds.
17 * If ``reload'' is non-zero, keep generating SIGALRM
18 * every ``reload'' microseconds after the first signal.
19 */
20unsigned
21ualarm(usecs, reload)
22 register unsigned usecs;
23 register unsigned reload;
24{
25 struct itimerval new, old;
26
27 new.it_interval.tv_usec = reload % USPS;
28 new.it_interval.tv_sec = reload / USPS;
29
30 new.it_value.tv_usec = usecs % USPS;
31 new.it_value.tv_sec = usecs / USPS;
32
33 if (setitimer(ITIMER_REAL, &new, &old) == 0)
34 return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
35 /* else */
36 return (-1);
37}