The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

longjmp - non-local goto

 SYNOPSIS



#include <setjmp.h>

void longjmp(jmp_buf env, int val);

 DESCRIPTION

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:

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.

 RETURN VALUE

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.

 ERRORS

No errors are defined.

 EXAMPLES

None.

 APPLICATION USAGE

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).

 FUTURE DIRECTIONS

None.

 SEE ALSO

setjmp(), sigaction(), siglongjmp(), sigsetjmp(), <setjmp.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]