File: sigint.c

package info (click to toggle)
libc-sparc 5.3.12-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 18,664 kB
  • ctags: 53,237
  • sloc: ansic: 181,379; asm: 5,080; makefile: 3,340; lex: 521; sh: 439; yacc: 401; awk: 28
file content (45 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <signal.h>
#include <errno.h>

/* Set `sig' bit if we allow interrupt on it. */ 
sigset_t _sigintr = 0;

int
siginterrupt (int sig, int flag)
{
  struct sigaction sa;

  if (sig < 1 || sig >= NSIG) {
    errno = EINVAL;
    return -1;
  }

  if (__sigaction (sig, (struct sigaction *)0, &sa))
    return -1;
 
  if (flag) {
    __sigaddset (&_sigintr, sig);
#ifdef SA_RESTART
    if (!(sa.sa_flags & SA_RESTART) && (sa.sa_flags & SA_INTERRUPT))
      return 0;
    sa.sa_flags |= SA_INTERRUPT;
    sa.sa_flags &= ~ SA_RESTART;
#else
    if (sa.sa_flags & SA_INTERRUPT) return 0;
    sa.sa_flags |= SA_INTERRUPT;
#endif
  }
  else {
    __sigdelset (&_sigintr, sig);
#ifdef SA_RESTART
    if ((sa.sa_flags & SA_RESTART) && !(sa.sa_flags & SA_INTERRUPT))
      return 0;
    sa.sa_flags &= ~ SA_INTERRUPT;
    sa.sa_flags |= SA_RESTART;
#else
    if (!(sa.sa_flags & SA_INTERRUPT)) return 0;
    sa.sa_flags &= ~ SA_INTERRUPT;
#endif
  }
  return __sigaction (sig, &sa, (struct sigaction *)0);
}