1 /* 2 * Copyright (c) 1985, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)ualarm.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/time.h> 13 #include <unistd.h> 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 } 40