17c478bd9Sstevel@tonic-gate /*
2*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
37c478bd9Sstevel@tonic-gate * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate */
57c478bd9Sstevel@tonic-gate
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate * Copyright (c) 1985 Regents of the University of California.
117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
15*7257d1b4Sraf #pragma ident "%Z%%M% %I% %E% SMI"
16*7257d1b4Sraf
17*7257d1b4Sraf #include "lint.h"
187c478bd9Sstevel@tonic-gate #include <sys/types.h>
197c478bd9Sstevel@tonic-gate #include <sys/time.h>
207c478bd9Sstevel@tonic-gate #include <unistd.h>
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate #define USPS 1000000 /* # of microseconds in a second */
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gate /*
257c478bd9Sstevel@tonic-gate * Generate a SIGALRM signal in ``usecs'' microseconds.
267c478bd9Sstevel@tonic-gate * If ``reload'' is non-zero, keep generating SIGALRM
277c478bd9Sstevel@tonic-gate * every ``reload'' microseconds after the first signal.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate useconds_t
ualarm(useconds_t usecs,useconds_t reload)307c478bd9Sstevel@tonic-gate ualarm(useconds_t usecs, useconds_t reload)
317c478bd9Sstevel@tonic-gate {
327c478bd9Sstevel@tonic-gate struct itimerval new, old;
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate new.it_interval.tv_usec = reload % USPS;
357c478bd9Sstevel@tonic-gate new.it_interval.tv_sec = reload / USPS;
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate new.it_value.tv_usec = usecs % USPS;
387c478bd9Sstevel@tonic-gate new.it_value.tv_sec = usecs / USPS;
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate if (setitimer(ITIMER_REAL, &new, &old) != 0)
417c478bd9Sstevel@tonic-gate return (0); /* no errors are defined */
427c478bd9Sstevel@tonic-gate return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
437c478bd9Sstevel@tonic-gate }
44