_signal.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <lib.h>
  2. #define signal _signal
  3. #include <signal.h>
  4. extern _PROTOTYPE(void (*_vectab[_NSIG]), (int)); /* array of funcs to catch signals */
  5. /* The definition of signal really should be
  6. * PUBLIC void (*signal(signr, func))()
  7. * but some compilers refuse to accept this, even though it is correct.
  8. * The only thing to do if you are stuck with such a defective compiler is
  9. * change it to
  10. * PUBLIC void *signal(signr, func)
  11. * and change ../h/signal.h accordingly.
  12. */
  13. PUBLIC void (*signal(signr, func))()
  14. int signr; /* which signal is being set */
  15. _PROTOTYPE( void (*func), (int)); /* pointer to function that catches signal */
  16. {
  17. int r;
  18. _PROTOTYPE( void (*old), (int));
  19. old = _vectab[signr - 1];
  20. _M.m6_i1 = signr;
  21. if (func == SIG_IGN || func == SIG_DFL)
  22. /* Keep old signal catcher until it is completely de-installed */
  23. _M.m6_f1 = func;
  24. else {
  25. /* Use new signal catcher immediately (old one may not exist) */
  26. _vectab[signr - 1] = func;
  27. _M.m6_f1 = _begsig;
  28. }
  29. r = _callx(MM, SIGNAL);
  30. if (r < 0) {
  31. _vectab[signr - 1] = old;/* undo any pre-installation */
  32. return((void (*) ()) r);
  33. }
  34. _vectab[signr - 1] = func; /* redo any pre-installation */
  35. if (r == 1) return(SIG_IGN);
  36. return(old);
  37. }