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) |
269a7923 | 9 | static char sccsid[] = "@(#)ualarm.c 5.4 (Berkeley) %G%"; |
cecf1c1c | 10 | #endif /* LIBC_SCCS and not lint */ |
63dcf418 S |
11 | |
12 | #include <sys/time.h> | |
13 | ||
14 | #define USPS 1000000 /* # of microseconds in a second */ | |
15 | ||
16 | /* | |
17 | * Generate a SIGALRM signal in ``usecs'' microseconds. | |
18 | * If ``reload'' is non-zero, keep generating SIGALRM | |
19 | * every ``reload'' microseconds after the first signal. | |
20 | */ | |
21 | unsigned | |
22 | ualarm(usecs, reload) | |
23 | register unsigned usecs; | |
24 | register unsigned reload; | |
25 | { | |
26 | struct itimerval new, old; | |
27 | ||
28 | new.it_interval.tv_usec = reload % USPS; | |
29 | new.it_interval.tv_sec = reload / USPS; | |
30 | ||
31 | new.it_value.tv_usec = usecs % USPS; | |
32 | new.it_value.tv_sec = usecs / USPS; | |
33 | ||
34 | if (setitimer(ITIMER_REAL, &new, &old) == 0) | |
35 | return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); | |
36 | /* else */ | |
37 | return (-1); | |
38 | } |