mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Moving libc from its separate repo into this one, minor resulting build fixes, and a hacky way to add -I for libc headers in builds.
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
/* signal( int, void (*)( int ) )
|
|
|
|
This file is part of the Public Domain C Library (PDCLib).
|
|
Permission is granted to use, modify, and / or redistribute at will.
|
|
*/
|
|
|
|
#include <signal.h>
|
|
#include <stdlib.h>
|
|
|
|
void (*_PDCLIB_sigabrt)( int ) = SIG_DFL;
|
|
void (*_PDCLIB_sigfpe)( int ) = SIG_DFL;
|
|
void (*_PDCLIB_sigill)( int ) = SIG_DFL;
|
|
void (*_PDCLIB_sigint)( int ) = SIG_DFL;
|
|
void (*_PDCLIB_sigsegv)( int ) = SIG_DFL;
|
|
void (*_PDCLIB_sigterm)( int ) = SIG_DFL;
|
|
|
|
void (*signal( int sig, void (*func)( int ) ) )( int )
|
|
{
|
|
void (*oldhandler)( int );
|
|
if ( sig <= 0 || func == SIG_ERR )
|
|
{
|
|
return SIG_ERR;
|
|
}
|
|
switch ( sig )
|
|
{
|
|
case SIGABRT:
|
|
oldhandler = _PDCLIB_sigabrt;
|
|
_PDCLIB_sigabrt = func;
|
|
break;
|
|
case SIGFPE:
|
|
oldhandler = _PDCLIB_sigfpe;
|
|
_PDCLIB_sigfpe = func;
|
|
break;
|
|
case SIGILL:
|
|
oldhandler = _PDCLIB_sigill;
|
|
_PDCLIB_sigill = func;
|
|
break;
|
|
case SIGINT:
|
|
oldhandler = _PDCLIB_sigint;
|
|
_PDCLIB_sigint = func;
|
|
break;
|
|
case SIGSEGV:
|
|
oldhandler = _PDCLIB_sigsegv;
|
|
_PDCLIB_sigsegv = func;
|
|
break;
|
|
case SIGTERM:
|
|
oldhandler = _PDCLIB_sigterm;
|
|
_PDCLIB_sigterm = func;
|
|
break;
|
|
default:
|
|
/* The standard calls for an unspecified "positive value". You
|
|
will probably want to define a specific value for this.
|
|
*/
|
|
_PDCLIB_errno = 1;
|
|
return SIG_ERR;
|
|
}
|
|
return oldhandler;
|
|
}
|