/* Signal handling <string.h>12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#ifndef _PDCLIB_SIGNAL_H7#define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H8#include "_PDCLIB_config.h"910/* Signals ------------------------------------------------------------------ */1112/* A word on signals, to the people using PDCLib in their OS projects.1314The definitions of the C standard leave about everything that *could* be15useful to be "implementation defined". Without additional, non-standard16arrangements, it is not possible to turn them into a useful tool.1718This example implementation chose to "not generate any of these signals,19except as a result of explicit calls to the raise function", which is20allowed by the standard but of course does nothing for the usefulness of21<signal.h>.2223A useful signal handling would:241) make signal() a system call that registers the signal handler with the OS252) make raise() a system call triggering an OS signal to the running process263) make provisions that further signals of the same type are blocked until27the signal handler returns (optional for SIGILL)28*/2930/* These are the values used by Linux. */3132/* Abnormal termination / abort() */33#define SIGABRT 634/* Arithmetic exception / division by zero / overflow */35#define SIGFPE 836/* Illegal instruction */37#define SIGILL 438/* Interactive attention signal */39#define SIGINT 240/* Invalid memory access */41#define SIGSEGV 1142/* Termination request */43#define SIGTERM 154445/* The following should be defined to pointer values that could NEVER point to46a valid signal handler function. (They are used as special arguments to47signal().) Again, these are the values used by Linux.48*/49#define SIG_DFL (void (*)( int ))050#define SIG_ERR (void (*)( int ))-151#define SIG_IGN (void (*)( int ))15253typedef _PDCLIB_sig_atomic sig_atomic_t;5455/* Installs a signal handler "func" for the given signal.56A signal handler is a function that takes an integer as argument (the signal57number) and returns void.5859Note that a signal handler can do very little else than:601) assign a value to a static object of type "volatile sig_atomic_t",612) call signal() with the value of sig equal to the signal received,623) call _Exit(),634) call abort().64Virtually everything else is undefind.6566The signal() function returns the previous installed signal handler, which67at program start may be SIG_DFL or SIG_ILL. (This implementation uses68SIG_DFL for all handlers.) If the request cannot be honored, SIG_ERR is69returned and errno is set to an unspecified positive value.70*/71void (*signal( int sig, void (*func)( int ) ) )( int );7273/* Raises the given signal (executing the registered signal handler with the74given signal number as parameter).75This implementation does not prevent further signals of the same time from76occuring, but executes signal( sig, SIG_DFL ) before entering the signal77handler (i.e., a second signal before the signal handler re-registers itself78or SIG_IGN will end the program).79Returns zero if successful, nonzero otherwise. */80int raise( int sig );8182#endif83848586