#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int _abterm=0;

static void sigill(int)
{
}
static void sigint(int)
{
}
static void sigfpe(int)
{
}
static void sigsegv(int)
{
}
static void sigterm(int)
{
	exit(EXIT_SUCCESS);
}
static void siguser1()
{
}
static void siguser2()
{
}
static void siguser3()
{
}
static void siguser()
{
}
static void sigabort(int)
{
	_abterm = 1;
	exit(EXIT_FAILURE);
}
static void (*deftab[NSIG])(int) = {
	 SIG_ERR,  SIG_ERR,	sigint,	 SIG_ERR,
	sigill,  SIG_ERR, SIG_ERR, SIG_ERR,
	sigfpe,  SIG_ERR, SIG_ERR, sigsegv,
	 SIG_ERR, SIG_ERR, SIG_ERR,sigterm,
	siguser1,siguser2, SIG_ERR, SIG_ERR,
	siguser3,SIG_ERR,sigabort 
};

static void (*sigtab[NSIG])(int);
#pragma startup siginit 149

static void siginit(void)
{
	int i;
	for (i=0; i < NSIG; i++)
		sigtab[i] = deftab[i];
}
void (*signal(int signum, void (*func)()))(int)
{
	void (*temp)(int);
	if (signum >= NSIG) {
		errno = EINVAL;
		return SIG_ERR;
	}
	temp = sigtab[signum];
	if (func == SIG_DFL) 
		sigtab[signum] = deftab[signum];
	else    /* SIG_IGN && SIG_ERR gets used as-is, 
                   otherwise func is a valid func */
		sigtab[signum] = func;
	return temp;
}
int raise(int sig)
{
	void (*temp)(int a) = sigtab[sig];
	if (temp == SIG_ERR)
		return 1;
	if (temp == SIG_IGN)
		return 0;
	(*temp)(sig);
	sigtab[sig] = deftab[sig];
	return 0;
}