1*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 2*0Sstevel@tonic-gate /* from UCB 5.1 85/06/05 */ 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gate /* 5*0Sstevel@tonic-gate * Copyright (c) 1985 Regents of the University of California. 6*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 7*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 8*0Sstevel@tonic-gate */ 9*0Sstevel@tonic-gate 10*0Sstevel@tonic-gate #include <sys/time.h> 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate #define USPS 1000000 /* # of microseconds in a second */ 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate /* 15*0Sstevel@tonic-gate * Generate a SIGALRM signal in ``usecs'' microseconds. 16*0Sstevel@tonic-gate * If ``reload'' is non-zero, keep generating SIGALRM 17*0Sstevel@tonic-gate * every ``reload'' microseconds after the first signal. 18*0Sstevel@tonic-gate */ 19*0Sstevel@tonic-gate unsigned ualarm(usecs,reload)20*0Sstevel@tonic-gateualarm(usecs, reload) 21*0Sstevel@tonic-gate register unsigned usecs; 22*0Sstevel@tonic-gate register unsigned reload; 23*0Sstevel@tonic-gate { 24*0Sstevel@tonic-gate struct itimerval new, old; 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate new.it_interval.tv_usec = reload % USPS; 27*0Sstevel@tonic-gate new.it_interval.tv_sec = reload / USPS; 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate new.it_value.tv_usec = usecs % USPS; 30*0Sstevel@tonic-gate new.it_value.tv_sec = usecs / USPS; 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate if (setitimer(ITIMER_REAL, &new, &old) == 0) 33*0Sstevel@tonic-gate return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); 34*0Sstevel@tonic-gate /* else */ 35*0Sstevel@tonic-gate return (-1); 36*0Sstevel@tonic-gate } 37