NAME
setjmp, longjmp, _setjmp, _longjmp - Saves and restores the
current execution context
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <setjmp.h>
int setjmp (
jmp_buf environment );
void longjmp (
jmp_buf environment,
int value );
int _setjmp (
jmp_buf environment );
void _longjmp (
jmp_buf environment,
int value );
PARAMETERS
environment
Specifies an address for a jmp_buf structure.
value Specifies any nonzero value.
DESCRIPTION
The setjmp() and longjmp() functions are useful when han-
dling errors and interrupts encountered in low-level func-
tions of a program.
The setjmp() function saves the current stack context and
signal mask in the buffer specified by the environment
parameter.
The longjmp() function restores the stack context and signal
mask that were saved by the setjmp() function in the
corresponding environment buffer. After the longjmp() func-
tion runs, program execution continues as if the correspond-
ing call to the setjmp() function had just returned the
value of the value parameter. The function that called the
setjmp() function must not have returned before the comple-
tion of the longjmp() function. The setjmp() function and
the longjmp() function save and restore the signal mask,
while _setjmp() and _longjmp() manipulate only the stack
context.
As it bypasses the usual function call and return mechan-
isms, the longjmp() function executes correctly in contexts
of interrupts, signals, and any of their associated
functions. However, if the longjmp() function 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 behavior is undefined.
NOTES
The reentrant versions of the setjmp() and longjmp() func-
tions are identical in behavior to the _setjmp() and
_longjmp()
The System V versions of the setjmp() and longjmp() func-
tions, which are equivalent to _setjmp() and _longjmp()
respectively, are also supported for compatibility. To use
the System V versions of setjmp() and longjmp(), you must
link with the libsys5 library before you link with libc.
AES Support Level:
Full use
CAUTION
If the longjmp() function is called with an environment
parameter that was not previously set by the setjmp() func-
tion, or if the function that made the corresponding call to
the setjmp() function has already returned, then the results
of the longjmp() function are undefined. If the longjmp()
function detects such a condition, it calls the longjmper-
ror() function. If longjmperror() returns, the program is
aborted. The default version of longjmperror() prints an
error message to standard error and returns. Users wishing
to exit more gracefully can write their own versions of the
longjmperror() program.
If automatic and register variables are changed after the
setjmp(), their values are indeterminate after the
longjmp(). You cannot assume that these variables are
restored to what they were when the setjmp() was called. Nor
can you assume that they are set to whatever value they had
when the function sequence containing the longjmp() was
started.
If you want them to retain the values they had when the
function sequence containing the longjmp() is started,
declare them as volatile.
RETURN VALUES
The setjmp() function returns a value of 0 (zero), unless
the return is from a call to the longjmp() function, in
which case setjmp() returns a nonzero value.
The longjmp() function cannot return 0 (zero) to the previ-
ous context. The value 0 is reserved to indicate the actual
return from the setjmp() function when first called by the
program. If the longjmp() function is passed a value parame-
ter of 0, then execution continues as if the corresponding
call to the setjmp() function had returned a value of 1. All
accessible data have values as of the time the longjmp()
function is called.
RELATED INFORMATION
Functions: siglongjmp(3), sigsetjmp(3)
Acknowledgement and Disclaimer