home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
lang
/
lsc30p4u.sit
/
unixsignal.c
< prev
Wrap
Text File
|
1989-01-15
|
3KB
|
129 lines
/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
/* This module implements an abbreviated version of signal() and its
related functions */
#ifndef _unixh_
#include "unix.h"
#endif
extern int errno;
extern int (*_key_int_sig_func_)();
extern void abort();
static void *sigptr[_SIGMAX+1]; /* array of signal pointers, initially 0 */
static char _initsigterm = 0; /* flag for special SIGTERM set up */
#line 0 dosigterm
static void dosigterm()
{register void (*calledfunc)() = sigptr[SIGTERM];
/* if non-zero, call this procedure on exit from application */
if (calledfunc)
(*calledfunc)(SIGTERM);
}
#line 0 signal
int (*signal(sig, func))()
int sig;
int (*func)();
{
int (*_last_sig_func_)();
/* SIGINT is presently supported as a special case for trapping ^c
and ^. (where ^ means the command (fan) key. ^c and ^. are
therefore invisible to the application and are swallowed when the
interrupt procedure is called. This was done so lots of unix
code would not get dragged in for those just using stdio. */
switch (sig)
{
case SIGINT:
_last_sig_func_= _key_int_sig_func_;
/* see if user wants to cause an exit on SIGINT */
if ((long)func == SIG_DFL)
_key_int_sig_func_ = (void*) abort;
else
if ((long)func == SIG_IGN)
_key_int_sig_func_ = 0; /* eliminate any set function */
else
_key_int_sig_func_ = func; /* set up "catch" function */
return (_last_sig_func_); /* return last catch function */
case SIGTERM:
/* enable sending a last signal on application termination */
if (!_initsigterm)
{
_initsigterm = 1;
_onexit(dosigterm);
}
default:
if ((sig > 0) && (sig <= _SIGMAX))
{
_last_sig_func_ = sigptr[sig];
/* see if user wants to cause an exit on signal */
if ((long)func == SIG_DFL)
sigptr[sig] = (void*) abort;
else
if ((long)func == SIG_IGN)
sigptr[sig] = 0; /* eliminate any set function */
else
sigptr[sig] = func; /* set up "catch" function */
return (_last_sig_func_); /* return last catch function */
}
if (sig == 0) return (0);
/* signal value out of range */
errno = EINVAL;
return ((void*)-1);
}
}
#line 0 kill
kill(pid, sig)
int pid, sig;
{
if ((sig > _SIGMAX) || (sig < 0))
{
/* signal value out of range */
errno = EINVAL;
return (-1);
}
if ((pid == getpid()) || (pid <= 0))
{register void (*calledfunc)() = sigptr[sig];
if (sig)
{
/* send a signal to ourself! */
sigptr[sig] = (void*) SIG_DFL;
if (calledfunc)
(*calledfunc)(sig);
}
return (0);
}
errno = ESRCH; /* no such process */
return (-1);
}