122123Smckusick /* 222123Smckusick * Copyright (c) 1985 Regents of the University of California. 3*35306Sbostic * All rights reserved. 4*35306Sbostic * 5*35306Sbostic * Redistribution and use in source and binary forms are permitted 6*35306Sbostic * provided that the above copyright notice and this paragraph are 7*35306Sbostic * duplicated in all such forms and that any documentation, 8*35306Sbostic * advertising materials, and other materials related to such 9*35306Sbostic * distribution and use acknowledge that the software was developed 10*35306Sbostic * by the University of California, Berkeley. The name of the 11*35306Sbostic * University may not be used to endorse or promote products derived 12*35306Sbostic * from this software without specific prior written permission. 13*35306Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35306Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35306Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622123Smckusick */ 1718339Sserge 1826609Sdonn #if defined(LIBC_SCCS) && !defined(lint) 19*35306Sbostic static char sccsid[] = "@(#)ualarm.c 5.3 (Berkeley) 08/02/88"; 20*35306Sbostic #endif /* LIBC_SCCS and not lint */ 2122123Smckusick 2218339Sserge #include <sys/time.h> 2318339Sserge 2418339Sserge #define USPS 1000000 /* # of microseconds in a second */ 2518339Sserge 2618339Sserge /* 2718339Sserge * Generate a SIGALRM signal in ``usecs'' microseconds. 2818339Sserge * If ``reload'' is non-zero, keep generating SIGALRM 2918339Sserge * every ``reload'' microseconds after the first signal. 3018339Sserge */ 3118339Sserge unsigned 3218339Sserge ualarm(usecs, reload) 3318339Sserge register unsigned usecs; 3418339Sserge register unsigned reload; 3518339Sserge { 3618339Sserge struct itimerval new, old; 3718339Sserge 3818339Sserge new.it_interval.tv_usec = reload % USPS; 3918339Sserge new.it_interval.tv_sec = reload / USPS; 4018339Sserge 4118339Sserge new.it_value.tv_usec = usecs % USPS; 4218339Sserge new.it_value.tv_sec = usecs / USPS; 4318339Sserge 4418339Sserge if (setitimer(ITIMER_REAL, &new, &old) == 0) 4518339Sserge return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); 4618339Sserge /* else */ 4718339Sserge return (-1); 4818339Sserge } 49