home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / bsd / sigint.c < prev   
Encoding:
C/C++ Source or Header  |  1994-01-10  |  1003 b   |  46 lines

  1. #include <signal.h>
  2. #include <errno.h>
  3.  
  4. /* Set `sig' bit if we allow interrupt on it. */ 
  5. sigset_t _sigintr = 0;
  6.  
  7. int
  8. siginterrupt (int sig, int flag)
  9. {
  10.   struct sigaction sa;
  11.  
  12.   if (sig < 1 || sig >= NSIG) {
  13.     errno = EINVAL;
  14.     return -1;
  15.   }
  16.  
  17.   if (__sigaction (sig, (struct sigaction *)0, &sa))
  18.     return -1;
  19.  
  20.   if (flag) {
  21.     __sigaddset (&_sigintr, sig);
  22. #ifdef SA_RESTART
  23.     if (!(sa.sa_flags & SA_RESTART) && (sa.sa_flags & SA_INTERRUPT))
  24.       return 0;
  25.     sa.sa_flags |= SA_INTERRUPT;
  26.     sa.sa_flags &= ~ SA_RESTART;
  27. #else
  28.     if (sa.sa_flags & SA_INTERRUPT) return 0;
  29.     sa.sa_flags |= SA_INTERRUPT;
  30. #endif
  31.   }
  32.   else {
  33.     __sigdelset (&_sigintr, sig);
  34. #ifdef SA_RESTART
  35.     if ((sa.sa_flags & SA_RESTART) && !(sa.sa_flags & SA_INTERRUPT))
  36.       return 0;
  37.     sa.sa_flags &= ~ SA_INTERRUPT;
  38.     sa.sa_flags |= SA_RESTART;
  39. #else
  40.     if (!(sa.sa_flags & SA_INTERRUPT)) return 0;
  41.     sa.sa_flags &= ~ SA_INTERRUPT;
  42. #endif
  43.   }
  44.   return __sigaction (sig, &sa, (struct sigaction *)0);
  45. }
  46.