1987-03-31 10:45:53 +00:00
|
|
|
/* $Header$ */
|
1987-01-27 15:57:55 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
static jmp_buf setjmpbuf;
|
|
|
|
|
1993-11-17 16:53:43 +00:00
|
|
|
static void
|
1987-01-27 15:57:55 +00:00
|
|
|
alfun(){
|
|
|
|
longjmp(setjmpbuf, 1);
|
|
|
|
} /* used with sleep() below */
|
|
|
|
|
|
|
|
sleep(n)
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
/* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */
|
|
|
|
unsigned oldalarm;
|
1993-11-17 16:53:43 +00:00
|
|
|
void (*oldsig)();
|
1987-01-27 15:57:55 +00:00
|
|
|
|
|
|
|
if (n <= 0) return;
|
|
|
|
if (setjmp(setjmpbuf)) {
|
|
|
|
signal(SIGALRM, oldsig);
|
|
|
|
alarm(oldalarm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
oldalarm = alarm(5000); /* Who cares how long, as long as it is long
|
|
|
|
enough
|
|
|
|
*/
|
|
|
|
if (oldalarm > n) oldalarm -= n;
|
1987-04-23 15:20:41 +00:00
|
|
|
else if (oldalarm) {
|
|
|
|
n = oldalarm;
|
|
|
|
oldalarm = 1;
|
1987-01-27 15:57:55 +00:00
|
|
|
}
|
|
|
|
oldsig = signal(SIGALRM, alfun);
|
|
|
|
alarm(n);
|
|
|
|
for (;;) {
|
|
|
|
/* allow for other handlers ... */
|
|
|
|
pause();
|
|
|
|
}
|
|
|
|
}
|