SETJMP(3)SETJMP(3)NAME
setjmp, longjmp, sigsetjmp, siglongjmp - non-local goto
SYNOPSIS
#include <setjmp.h>
int setjmp(jmp_buf env);
void longjmp( jmp_buf env, int val);
(AVAILABLE ONLY IN POSIX)
int sigsetjmp(jmp_buf env, int savemask);
void siglongjmp(jmp_buf env, int val);
(AVAILABLE ONLY IN BSD)
int _setjmp(jmp_buf env);
void _longjmp(jmp_buf env, int val);
DESCRIPTION
These routines are useful for dealing with errors and interrupts
encountered in a low-level subroutine of a program.
Setjmp saves its stack environment in env for later use by longjmp. If
the return is from a direct invocation, setjmp returns the value zero.
If the return is from a call to longjmp, setjmp returns a nonzero
value.
Longjmp restores the environment saved by the last call of setjmp in
the same invocation of the program, with the corresponding env
argument. It then returns in such a way that execution continues as if
the call of setjmp had just returned the value val to the function that
invoked setjmp, which must not itself have returned in the interim.
All accessible data have values as of the time longjmp was called,
except that the values of objects of automatic storage duration that
are local to the function containing the invocation of the
corresponding setjmp that do not have volatile-qualified type and have
been changed between the setjmp invocation and longjmp call are
indeterminate.
The routines sigsetjmp and siglongjmp are identical to setjmp and
longjmp but allow the calling process to control its signal mask. If
the value of savemask is not zero, sigsetjmp saves the current signal
mask of the process as part of the calling environment. If savemask is
zero sigsetjmp is identical to setjmp. If the env argument was
initialized by a call to the sigsetjmp function with a nonzero savemask
argument, siglongjmp restores the saved signal mask.
The BSD functions _setjmp and _longjmp are equivalent to sigsetjmp with
a savemask of 0 and siglongjmp, respectively.
RETURN VALUE
After a long jump is completed, program execution continues as if the
corresponding invocation of a set-jump has just returned the value
specified by val. A long jump cannot cause the set-jmp function to
return the value 0; if val is 0, the set-jmp function returns the value
1.
ERRORS
If the contents of the jmp_buf are corrupted, or correspond to an
environment that has already returned, longjmp calls the routine
longjmperror. If longjmperror returns the program is aborted. The
default version of longjmperror prints the message ``longjmp botch'' to
standard error and returns. User programs wishing to exit more
gracefully can write their own versions of longjmperror.
SEE ALSOsigaction(2P), sigprocmask(2P), sigsuspend(2P), sigvec(2), sigstack(2),
signal(3)4th Berkeley Distribution August 1, 1992 SETJMP(3)