#include <setjmp.h> int setjmp(jmp_buf env); void longjmp( jmp_buf env, int val);
int sigsetjmp(jmp_buf env, int savemask); void siglongjmp(jmp_buf env, int val);
int _setjmp(jmp_buf env); void _longjmp(jmp_buf env, int val);
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.
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.