longjmp - non-local goto
#include <setjmp.h> void longjmp(jmp_buf env, int val);
The longjmp() function restores the environment saved by the most recent invocation of setjmp() in the same thread, with the corresponding jmp_buf argument. If there is no such invocation, or if the function containing the invocation of setjmp() has terminated execution in the interim, the behaviour is undefined. It is unspecified whether longjmp() restores the signal mask, leaves the signal mask unchanged or restores it to its value at the time setjmp() was called.
All accessible objects have values as of the time setjmp() was called, except that the values of objects of automatic storage duration are indeterminate if they meet all the following conditions:
- They are local to the function containing the corresponding setjmp() invocation.
- They do not have volatile-qualified type.
- They are changed between the setjmp() invocation and longjmp() call.
As it bypasses the usual function call and return mechanisms, longjmp() will execute correctly in contexts of interrupts, signals and any of their associated functions. However, if longjmp() is invoked from a nested signal handler (that is, from a function invoked as a result of a signal raised during the handling of another signal), the behaviour is undefined.
The effect of a call to longjmp() where initialisation of the jmp_buf structure was not performed in the calling thread is undefined.
After longjmp() is completed, program execution continues as if the corresponding invocation of setjmp() had just returned the value specified by val. The longjmp() function cannot cause setjmp() to return 0; if val is 0, setjmp() returns 1.
No errors are defined.
Applications whose behaviour depends on the value of the signal mask should not use longjmp() and setjmp(), since their effect on the signal mask is unspecified, but should instead use the siglongjmp() and sigsetjmp() functions (which can save and restore the signal mask under application control).
setjmp(), sigaction(), siglongjmp(), sigsetjmp(), <setjmp.h>.
Derived from Issue 1 of the SVID.