setjmp(3) — Subroutines
OSF
NAME
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
environmentSpecifies an address for a jmp_buf structure.
valueSpecifies any nonzero value.
DESCRIPTION
The setjmp() and longjmp() functions are useful when handling errors and interrupts encountered in low-level functions 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() function runs, program execution continues as if the corresponding 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 completion 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 mechanisms, 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() functions are identical in behavior to the _setjmp() and _longjmp()
The System V versions of the setjmp() and longjmp() functions, 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() function, 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 longjmperror() 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.
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 previous 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 parameter 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)