summaryrefslogtreecommitdiffstats
path: root/bsdsignal.c
blob: 92de9999901aabcd4612e625a19b9d19e42e77b6 (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
/*
 * bsdsignal.c
 *
 * Use sigaction() to simulate BSD signal()
 */

#include "config.h"

void (*bsd_signal(int signum, void (*handler)(int)))(int)
{
  struct sigaction action, oldaction;

  memset(&action, 0, sizeof action);
  action.sa_handler = handler;
  sigemptyset(&action.sa_mask);
  sigaddset(&action.sa_mask, signum);
  action.sa_flags = SA_RESTART;
  
  if (sigaction(signum, &action, &oldaction) == -1) {
#ifdef SIG_ERR
    return SIG_ERR;
#else
    return NULL;
#endif
  }

  return oldaction.sa_handler;
}