/* nap.c Larn is copyrighted 1986 by Noah Morgan. */
* routine to take a nap for n milliseconds
if (x
<=0) return; /* eliminate chance for infinite loop */
if (x
> 999) sleep(x
/1000); else napms(x
);
napms(x
) /* do nothing */
/* napms - sleep for time milliseconds - uses times() */
/* this assumes that times returns a relative time in 60ths of a second */
/* this will do horrible things if your times() returns seconds! */
long matchclock
, times();
if (time
<=0) time
=1; /* eliminate chance for infinite loop */
if ((matchclock
= times(&stats
)) == -1 || matchclock
== 0)
return; /* error, or BSD style times() */
matchclock
+= (time
/ 17); /*17 ms/tic is 1000 ms/sec / 60 tics/sec */
while(matchclock
< times(&stats
))
/* This must be BSD 4.2! */
#define bit(_a) (1<<((_a)-1))
/* napms - sleep for time milliseconds - uses setitimer() */
struct itimerval timeout
;
timerclear(&timeout
.it_interval
);
timeout
.it_value
.tv_sec
= time
/ 1000;
timeout
.it_value
.tv_usec
= (time
% 1000) * 1000;
oldsig
= sigblock(bit(SIGALRM
));
setitimer(ITIMER_REAL
, &timeout
, (struct itimerval
*)0);
oldhandler
= signal(SIGALRM
, nullf
);
signal(SIGALRM
, oldhandler
);
/* napms - sleep for time milliseconds - uses ftime() */
/* assumed to be BSD UNIX */
unsigned short matchmilli
;
register struct timeb
*tp
= & _gtime
;
matchmilli
= tp
->millitm
+ time
;
while (matchmilli
>= 1000)
if ((tp
->time
> matchtime
) ||
((tp
->time
== matchtime
) && (tp
->millitm
>= matchmilli
)))
static napms(time
) int time
; {} /* do nothing, forget it */