home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / kill.c < prev    next >
C/C++ Source or Header  |  1993-02-22  |  1KB  |  62 lines

  1. /* kill() for MiNT */
  2.  
  3. #include <stdlib.h>
  4. #include <errno.h>
  5. #include <osbind.h>
  6. #include <signal.h>
  7. #include <unistd.h>
  8. #include <mintbind.h>
  9.  
  10. extern int __mint;
  11.  
  12. /* vector of signal handlers (for TOS) */
  13. extern __Sigfunc _sig_handler[];    /* in signal.c */
  14.  
  15. /* vector giving which signals are currently blocked from delivery (for TOS) */
  16. extern long _sigmask;            /* in signal.c */
  17.  
  18. /* which signals are pending? */
  19. extern long _sigpending;
  20.  
  21. int
  22. kill(pid, sig)
  23.     int pid, sig;
  24. {
  25.     long r;
  26.     __Sigfunc hndle;
  27.  
  28.     if (__mint) {
  29.         r = Pkill(pid, sig);
  30.         if (r < 0) {
  31.             errno = (int) -r;
  32.             return -1;
  33.         }
  34.     } else {
  35.         if (sig < 0 || sig >= NSIG || (pid && pid != getpid())) {
  36.             errno = ERANGE;
  37.             return -1;
  38.         }
  39.         hndle = _sig_handler[sig];
  40.         if (hndle == SIG_IGN)
  41.             return 0;
  42.     /* check here for masked signals */
  43.         else if (sig != SIGKILL && (_sigmask & (1L << sig)))
  44.             _sigpending |= (1L << sig);
  45.         else {
  46.             _sigpending &= ~(1L << sig);
  47.             if (hndle == SIG_DFL) {
  48.                 switch (sig) {
  49.                 case SIGCONT:
  50.                 case SIGCHLD:
  51.                     return 0;
  52.                 default:
  53.                     exit(sig << 8);
  54.                 }
  55.             } else {
  56.                 (*hndle)(sig);
  57.             }
  58.         }
  59.     }
  60.     return 0;
  61. }
  62.