sigfpe(3) C LIBRARY FUNCTIONS sigfpe(3)
NAME
sigfpe - signal handling for specific SIGFPE codes
SYNOPSIS
cc [ flag... ] file ... -lucb
#include <signal.h>
#include <floatingpoint.h>
sigfpehandlertype sigfpe(code, hdl)
sigfpecodetype code;
sigfpehandlertype hdl;
DESCRIPTION
This function allows signal handling to be specified for
particular SIGFPE codes. A call to sigfpe defines a new
handler hdl for a particular SIGFPE code and returns the old
handler as the value of the function sigfpe. Normally
handlers are specified as pointers to functions; the special
cases SIGFPEIGNORE, SIGFPEABORT, and SIGFPEDEFAULT allow
ignoring, specifying core dump using abort(3), or default
handling respectively. For these IEEE-related codes:
FPEFLTINEXTRAP fp_inexact floating inexact result
FPEFLTDIVTRAP fp_division floating division by zero
FPEFLTUNDTRAP fp_underflow floating underflow
FPEFLTOVFTRAP fp_overflow floating overflow
FPEFLTBSUNTRAP fp_invalid branch or set on unordered
FPEFLTOPERRTRAP fp_invalid floating operand error
FPEFLTNANTRAP fp_invalid floating Not-A-Number
default handling is defined to be to call the handler speci-
fied to ieeehandler(3M). For all other SIGFPE codes,
default handling is to core dump using abort(3). The compi-
lation option -ffpa causes fpa recomputation to replace the
default abort action for code FPEFPAERROR. Note:
SIGFPEDEFAULT will restore abort rather than FPA recomputa-
tion for this code. Three steps are required to intercept
an IEEE-related SIGFPE code with sigfpe:
1) Set up a handler with sigfpe.
2) Enable the relevant IEEE trapping capability in
the hardware, perhaps by using assembly-language
instructions.
3) Perform a floating-point operation that generates
the intended IEEE exception.
Unlike ieeehandler(3M), sigfpe never changes floating-point
hardware mode bits affecting IEEE trapping. No IEEE-related
SIGFPE signals will be generated unless those hardware mode
bits are enabled. SIGFPE signals can be handled using
sigvec(2), signal(3), sigfpe(3), or ieeehandler(3M). In a
particular program, to avoid confusion, use only one of
these interfaces to handle SIGFPE signals.
Last change: BSD Compatibility Package 1
sigfpe(3) C LIBRARY FUNCTIONS sigfpe(3)
EXAMPLE
A user-specified signal handler might look like this:
void samplehandler( sig, code, scp, addr )
int sig ; /* sig == SIGFPE always */
int code ;
struct sigcontext *scp ;
char *addr ;
{
/*
Sample user-written sigfpe code handler.
Prints a message and continues.
struct sigcontext is defined in <signal.h>.
*/
printf(" ieee exception code %x occurred at pc %X \n",
code,scp->scpc);
}
and it might be set up like this:
extern void samplehandler;
main
{
sigfpehandlertype hdl, oldhandler1, oldhandler2;
/*
* save current overflow and invalid handlers; set the new
* overflow handler to samplehandler and set the new
* invalid handler to SIGFPEABORT (abort on invalid)
*/
hdl = (sigfpehandlertype) samplehandler;
oldhandler1 = sigfpe(FPEFLTOVFTRAP, hdl);
oldhandler2 = sigfpe(FPEFLTOPERRTRAP, SIGFPEABORT);
...
/*
* restore old overflow and invalid handlers
*/
sigfpe(FPEFLTOVFTRAP, oldhandler1);
sigfpe(FPEFLTOPERRTRAP, oldhandler2);
}
FILES
/usr/include/floatingpoint.h
/usr/include/signal.h
SEE ALSO
sigvec(2), floatingpoint(3), ieeehandler(3M), signal(3),
abort(3C) in the Programmer's Reference Manual.
RETURN VALUE
sigfpe returns BADSIG if code is not zero or a defined
SIGFPE code.
Last change: BSD Compatibility Package 2