|
|
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: unsigned sltime; ! 12: int (*alsig)() = SIG_DFL; ! 13: ! 14: if (n==0) ! 15: return; ! 16: altime = alarm(1000); /* time to maneuver */ ! 17: if (setjmp(jmp)) { ! 18: signal(SIGALRM, alsig); ! 19: if (sltime) { ! 20: kill(getpid(), SIGALRM); ! 21: sleep(sltime); ! 22: return; ! 23: } ! 24: alarm(altime); ! 25: return; ! 26: } ! 27: sltime = 0; ! 28: if (altime) { ! 29: if (altime < n) { ! 30: sltime = n - altime; ! 31: n -= altime; ! 32: } else { ! 33: altime -= n; ! 34: if (altime == 0) ! 35: altime = 1; ! 36: } ! 37: } ! 38: alsig = signal(SIGALRM, sleepx); ! 39: alarm(n); ! 40: for(;;) ! 41: pause(); ! 42: /*NOTREACHED*/ ! 43: } ! 44: ! 45: static ! 46: sleepx() ! 47: { ! 48: longjmp(jmp, 1); ! 49: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.