#include <lcjmp.h> void onjmpout(jmp_buf env, int code, target);
onjmpout
requests interception of calls to longjmp
that could
terminate the calling function. If a call to longjmp
is later
intercepted, control is passed to the target
label. The env
and code
variables are modified to indicate the target and code
specified by the intercepted longjmp
so that it can be reissued by
the intercepting routine.
onjmpout
sets the code
variable to 0 on completion. Because
interception of a jump assigns the code
variable a value other than 0, it can be tested elsewhere
to determine whether interception has taken place.
After a call to longjmp
is intercepted, onjmpout
must be
reissued if you want continued interception.
Because exit
is implemented as a longjmp
to the caller of
main
, you use onjmpout
to intercept program exit.
onjmpout
has no return value.
auto
and register
, whose values are
changed between the onjmpout
and longjmp
calls, have
indeterminate values after the branch to target
unless declared
volatile
.
onjmpout
is implemented as a macro and should not be used in any
position where a value is required.
onjmpout
is implemented as
#define onjmpout(e, c, t) if (c = blkjmp(e)) goto t
onjmpout
:
#include <lcjmp.h> jmp_buf env; int jmpcode; /* Intercept abnormal exits. */ onjmpout(env, jmpcode, cleanup); . . . cleanup: /* Clean up after attempted exit. */ . . . longjmp(env, jmpcode); /* And then reissue the jump. */
blkjmp
, longjmp
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.