summaryrefslogtreecommitdiff
path: root/libc/signal/bsd_sig.c
blob: 405447eae77174dfec0dacc8f1a68cec9a7b57ce (plain)
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
#define __USE_BSD_SIGNAL

#include <signal.h>

#undef signal

/* The `sig' bit is set if the interrupt on it
 * is enabled via siginterrupt (). */
extern sigset_t _sigintr;

__sighandler_t
__bsd_signal (int sig, __sighandler_t handler)
{
  int ret;
  struct sigaction action, oaction;
  action.sa_handler = handler;
  __sigemptyset (&action.sa_mask);
  if (!__sigismember (&_sigintr, sig)) {
#ifdef SA_RESTART
    action.sa_flags = SA_RESTART;
#else
    action.sa_flags = 0;
#endif
  }
  else {
#ifdef SA_INTERRUPT
    action.sa_flags = SA_INTERRUPT;
#else
    action.sa_flags = 0;
#endif
  }
  ret = sigaction (sig, &action, &oaction); 
  return (ret == -1) ? SIG_ERR : oaction.sa_handler;
}