.TH longjmp() "" "" "General Function (libc)"
.PC "Perform a non-local goto"
.B "#include <setjmp.h>"
\fBint longjmp(\fIenv\^\fB, \fIrval\^\fB)\fR
\fBjmp_buf \fIenv\^\fB; int \fIrval\^\fB;\fR
.PP
The function call is the only mechanism that C provides to
transfer control between functions.
This mechanism is inadequate for some purposes, such as handling unexpected
errors or interrupts at lower levels of a program.
To answer this need, \fBlongjmp\fR provides
a non-local \fIgoto\fR.
.PP
\fBlongjmp()\fR restores an environment that had been
saved by a previous call to the function \fBsetjmp()\fR.
It returns the value \fIrval\fR to the caller of \fBsetjmp()\fR,
just as if the \fBsetjmp()\fR call had just returned.
Note that
\fBlongjmp()\fR must not restore the environment
of a routine that has already returned.
.II jmp_buf
The type declaration for \fBjmp_buf\fR is in the header file \fBsetjmp.h\fR.
The environment saved includes the program counter, stack pointer, and stack
frame.
These routines do not restore register variables in the environment
returned.
.SH Example
For an example of this function, see the entry for
.BR setjmp() .
.SH "See Also"
.Xr "libc," libc
.Xr "setjmp()," setjmp
.Xr "siglongjmp()" siglongjm
.br
\*(AS, \(sc7.6.2.1
.br
\*(PX Standard, \(sc8.1
.SH Notes
Programmers should note that many user-level routines cannot
be interrupted and reentered safely.
For that reason, improper use of
.B longjmp()
and
.B setjmp()
can result in the creation of mysterious and irreproducible bugs.
Do not attempt to use
.B longjmp()
within an exception handler.
