home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
NETWORK
/
ISP
/
bind.4.8.3.lzh
/
BIND483
/
RES
/
signal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-31
|
1KB
|
64 lines
#include <signal.h>
typedef int (*pfi)();
#define SIGHANDS 32
int siginit;
int nhands;
struct sighand {int signo; pfi action;} sighands[SIGHANDS];
static int catch();
pfi signal(sig, func)
int sig;
pfi func;
{
register struct sighand *sp;
pfi p = SIG_DFL;
if(!siginit) {
siginit = 1;
intercept(catch);
}
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sp->signo == sig) {
p = sp->action;
sp->action = func;
return p;
}
}
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sp->action == SIG_DFL) {
sp->signo = sig;
sp->action = func;
return SIG_DFL;
}
}
return (pfi)-1;
}
static catch(sig)
int sig;
{
register struct sighand *sp;
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sig == sp->signo) {
/* note the sys V bug of removing the handler is not done */
/* (bsd does not have this bug) */
if(sp->action == SIG_IGN) return;
if(sp->action == SIG_DFL) break;
(*sp->action)(sig);
return;
}
}
switch(sig) {
case SIGWAKE:
return;
default:
exit(sig);
}
}