X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2Fsignal%2Fraise.c;fp=platform%2Fexample%2Ffunctions%2Fsignal%2Fraise.c;h=b16249c2ee75c0dc1941b9944a8ef7bbe0f17f38;hb=d2c7499692ec324dee9fa2e81942fd6478ee24f5;hp=0000000000000000000000000000000000000000;hpb=5b6ac4fcc65f0a5de1e4f51ef2af243c1eef8e7c;p=pdclib.old diff --git a/platform/example/functions/signal/raise.c b/platform/example/functions/signal/raise.c new file mode 100644 index 0000000..b16249c --- /dev/null +++ b/platform/example/functions/signal/raise.c @@ -0,0 +1,71 @@ +/* $Id$ */ + +/* raise( int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +#include + +extern void (*_PDCLIB_sigabrt)( int ); +extern void (*_PDCLIB_sigfpe)( int ); +extern void (*_PDCLIB_sigill)( int ); +extern void (*_PDCLIB_sigint)( int ); +extern void (*_PDCLIB_sigsegv)( int ); +extern void (*_PDCLIB_sigterm)( int ); + +int raise( int sig ) +{ + void (*sighandler)( int ); + switch ( sig ) + { + case SIGABRT: + sighandler = _PDCLIB_sigabrt; + break; + case SIGFPE: + sighandler = _PDCLIB_sigfpe; + break; + case SIGILL: + sighandler = _PDCLIB_sigill; + break; + case SIGINT: + sighandler = _PDCLIB_sigint; + break; + case SIGSEGV: + sighandler = _PDCLIB_sigsegv; + break; + case SIGTERM: + sighandler = _PDCLIB_sigterm; + break; + default: + /* TODO: Implement. */ + break; + } + if ( sighandler == SIG_DFL ) + { + _Exit( EXIT_FAILURE ); + } + else if ( sighandler != SIG_IGN ) + { + sighandler = signal( sig, SIG_DFL ); + sighandler( sig ); + } + return 0; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; +} +#endif