|
|
1.1 ! root 1: #include <signal.h> ! 2: #include <setjmp.h> ! 3: ! 4: static jmp_buf jmp; ! 5: ! 6: sleep(n) ! 7: unsigned n; ! 8: { ! 9: int sleepx(); ! 10: unsigned altime; ! 11: int (*alsig)() = SIG_DFL; ! 12: ! 13: if (n==0) ! 14: return; ! 15: altime = alarm(1000); /* time to maneuver */ ! 16: if (setjmp(jmp)) { ! 17: signal(SIGALRM, alsig); ! 18: alarm(altime); ! 19: return; ! 20: } ! 21: if (altime) { ! 22: if (altime > n) ! 23: altime -= n; ! 24: else { ! 25: n = altime; ! 26: altime = 1; ! 27: } ! 28: } ! 29: alsig = signal(SIGALRM, sleepx); ! 30: alarm(n); ! 31: for(;;) ! 32: pause(); ! 33: /*NOTREACHED*/ ! 34: } ! 35: ! 36: static ! 37: sleepx() ! 38: { ! 39: longjmp(jmp, 1); ! 40: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.