Commit | Line | Data |
---|---|---|
b8f253e8 KM |
1 | /* |
2 | * Copyright (c) 1985 Regents of the University of California. | |
cecf1c1c KB |
3 | * All rights reserved. |
4 | * | |
269a7923 | 5 | * %sccs.include.redist.c% |
b8f253e8 KM |
6 | */ |
7 | ||
2ce81398 | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
c5980113 | 9 | static char sccsid[] = "@(#)ualarm.c 5.5 (Berkeley) %G%"; |
cecf1c1c | 10 | #endif /* LIBC_SCCS and not lint */ |
63dcf418 S |
11 | |
12 | #include <sys/time.h> | |
c5980113 | 13 | #include <unistd.h> |
63dcf418 S |
14 | |
15 | #define USPS 1000000 /* # of microseconds in a second */ | |
16 | ||
17 | /* | |
18 | * Generate a SIGALRM signal in ``usecs'' microseconds. | |
19 | * If ``reload'' is non-zero, keep generating SIGALRM | |
20 | * every ``reload'' microseconds after the first signal. | |
21 | */ | |
22 | unsigned | |
23 | ualarm(usecs, reload) | |
24 | register unsigned usecs; | |
25 | register unsigned reload; | |
26 | { | |
27 | struct itimerval new, old; | |
28 | ||
29 | new.it_interval.tv_usec = reload % USPS; | |
30 | new.it_interval.tv_sec = reload / USPS; | |
31 | ||
32 | new.it_value.tv_usec = usecs % USPS; | |
33 | new.it_value.tv_sec = usecs / USPS; | |
34 | ||
35 | if (setitimer(ITIMER_REAL, &new, &old) == 0) | |
36 | return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); | |
37 | /* else */ | |
38 | return (-1); | |
39 | } |