1 /* nap.c Larn is copyrighted 1986 by Noah Morgan. */
2 /* $FreeBSD: src/games/larn/nap.c,v 1.4 1999/11/16 02:57:23 billf Exp $ */
14 * routine to take a nap for n milliseconds
19 if (x<=0) return; /* eliminate chance for infinite loop */
22 if (x > 999) sleep(x/1000); else napms(x);
29 napms(x) /* do nothing */
35 /* napms - sleep for time milliseconds - uses times() */
36 /* this assumes that times returns a relative time in 60ths of a second */
37 /* this will do horrible things if your times() returns seconds! */
41 long matchclock, times();
44 if (time<=0) time=1; /* eliminate chance for infinite loop */
45 if ((matchclock = times(&stats)) == -1 || matchclock == 0)
46 return; /* error, or BSD style times() */
47 matchclock += (time / 17); /*17 ms/tic is 1000 ms/sec / 60 tics/sec */
49 while(matchclock < times(&stats))
56 /* This must be BSD 4.2! */
58 #define bit(_a) (1<<((_a)-1))
64 /* napms - sleep for time milliseconds - uses setitimer() */
68 struct itimerval timeout;
72 if (time <= 0) return;
74 timerclear(&timeout.it_interval);
75 timeout.it_value.tv_sec = time / 1000;
76 timeout.it_value.tv_usec = (time % 1000) * 1000;
78 oldsig = sigblock(bit(SIGALRM));
79 setitimer(ITIMER_REAL, &timeout, (struct itimerval *)0);
80 oldhandler = signal(SIGALRM, nullf);
82 signal(SIGALRM, oldhandler);
87 /* napms - sleep for time milliseconds - uses ftime() */
92 /* assumed to be BSD UNIX */
95 unsigned short matchmilli;
96 struct timeb *tp = & _gtime;
98 if (time <= 0) return;
100 matchmilli = tp->millitm + time;
101 matchtime = tp->time;
102 while (matchmilli >= 1000)
111 if ((tp->time > matchtime) ||
112 ((tp->time == matchtime) && (tp->millitm >= matchmilli)))
118 static napms(time) int time; {} /* do nothing, forget it */