51 lines
1.3 KiB
C
Executable File
51 lines
1.3 KiB
C
Executable File
/*
|
|
* Copyright (c) 1995, by Sun Microsystems, Inc.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
|
|
/* All Rights Reserved */
|
|
|
|
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
|
|
/* The copyright notice above does not evidence any */
|
|
/* actual or intended publication of such source code. */
|
|
|
|
/*
|
|
* Copyright (c) 1985 Regents of the University of California.
|
|
* All rights reserved. The Berkeley software License Agreement
|
|
* specifies the terms and conditions for redistribution.
|
|
*/
|
|
/* Portions Copyright(c) 1988, Sun Microsystems Inc. */
|
|
/* All Rights Reserved */
|
|
|
|
#pragma ident "@(#)ualarm.c 1.2 95/03/02 SMI" /* SVr4.0 1.1 */
|
|
|
|
/*LINTLIBRARY*/
|
|
#include "synonyms.h"
|
|
|
|
#include <sys/time.h>
|
|
#include <unistd.h>
|
|
|
|
#define USPS 1000000 /* # of microseconds in a second */
|
|
|
|
/*
|
|
* Generate a SIGALRM signal in ``usecs'' microseconds.
|
|
* If ``reload'' is non-zero, keep generating SIGALRM
|
|
* every ``reload'' microseconds after the first signal.
|
|
*/
|
|
unsigned int
|
|
ualarm(unsigned int usecs, unsigned int reload)
|
|
{
|
|
struct itimerval new, old;
|
|
|
|
new.it_interval.tv_usec = reload % USPS;
|
|
new.it_interval.tv_sec = reload / USPS;
|
|
|
|
new.it_value.tv_usec = usecs % USPS;
|
|
new.it_value.tv_sec = usecs / USPS;
|
|
|
|
if (setitimer(ITIMER_REAL, &new, &old) != 0)
|
|
return (-1);
|
|
return (old.it_value.tv_sec * USPS + old.it_value.tv_usec);
|
|
}
|